Menu Close

Find atleast one duplicate number in the array.

Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.

Input: [3,1,3,4,2]

Output: 3
def duply(Nums,N):
    temp=[]
    for i in range(N):
        temp.append(Nums.count(Nums[i]))
    print(Nums[temp.index(max(temp))])

Arry=list(map(int,input("Nums : ").split(' ')))
n=len(Arry)
duply(Arry,n)

Input_1:
Nums : 1 3 4 2 2

Output:
2


Input_2:
Nums : 3 1 3 4 2

Output:
3


Input_3:
Nums : 1 1

Output:
1


Input_4:
Nums : 1 1 2

Output:
1


Input_5:
Nums : 1 2 3 1 4 5

Output:
1


Input_6:
Nums : 100 250 600 750 250 500

Output:
250


Illustration of the Output:

Executed using python3 linux

More Q