Duplicate in array
Given an array of integers of size n which contains numbers from 0 to n - 2. Each number is present at least once. That is, if n = 5, numbers from 0 to 3 is present in the given array at least once and one number is present twice. You need to find and return that duplicate number present in the array.
Assume, duplicate number is always present in the array.
Input format :
Output Format :
Constraints :
1 <= n <= 10^6
Sample Input:
Sample Output:
7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
def MissingNumber(arr): | |
res=Counter(arr) | |
return max(res, key=res.get) | |
# Main | |
n=int(input()) | |
arr=list(int(i) for i in input().strip().split(' ')) | |
ans=MissingNumber(arr) | |
print(ans) |
Comments
Post a Comment
Please give us your valuable feedback