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:
More Q
- Determine if a person could attend all meetings in given interval times.
- Find the volume of a volley ball
- Find the maximum score obtained at the end of colour chess grid game.
- Find the number of pairs if positive integers with condition is even.
- Return the largest subset such that every pair meets the given condition.
- Find the number of index triplets that satisfy given condition.
- Handling multiple queries using array – sum, update, range.
- Find all the sequences that occur more than once in DNA molecule.
- Find the biggest number.
- Sum of cube of each number is again equal to the number then it is an Armstrong number.
- Hello World.
- Calculate the Cube Root.
- Find the count of consecutive 1’s present in array.
- Return an array with athletes relative ranks according to the score.
- Return a string of its base 7 representation.
- Return kth largest element in sorted order.
- Find all repeated elements in the array.
- Find atleast one duplicate number in the array.
- Find the maximum result of = a XOR b.