0

How to find repeated numbers in an array if it contains multiple duplicates?

In that case, an array contains only one duplicate but what if it contains multiple duplicates? Suppose, an array contains n numbers ranging from 0 to n-1 and there are 5 duplicates on it, how to find ?

12th Oct 2021, 1:12 PM
Hambire Ranjeet
Hambire Ranjeet - avatar
4 Respostas
12th Oct 2021, 1:26 PM
Simon Sauter
Simon Sauter - avatar
+ 2
l=[1,3,4,4,5,7,7,7,8,9,78,46] print({i for i in l if l.count(i) > 1 }) will print {4,7}
12th Oct 2021, 2:04 PM
ubai
ubai - avatar
0
Use array elements as key and their frequency as value with dictionary
12th Oct 2021, 1:16 PM
Mohd Aadil
Mohd Aadil - avatar
0
arr = [1, 2, 3, 4, 2, 7, 8, 8, 3]     print("Duplicate elements: ") for i in range(0, len(arr)):         for j in range(+1, len(arr)):             if(arr[i] == arr[j]):                 print(arr[j])
12th Oct 2021, 1:30 PM
Hambire Ranjeet
Hambire Ranjeet - avatar