Skip to content

Commit ea7fcc9

Browse files
Add files via upload
1 parent bcd9cd9 commit ea7fcc9

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Geeksforgeeks_Array Duplicates.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Array Duplicates
2+
# Difficulty: EasyAccuracy: 18.95%Submissions: 876K+Points: 2Average Time: 20m
3+
# Given an array arr[] of size n, containing elements from the range 1 to n, and each element appears at most twice, return an array of all the integers that appears twice.
4+
5+
# Note: You can return the elements in any order but the driver code will print them in sorted order.
6+
7+
# Examples:
8+
9+
# Input: arr[] = [2, 3, 1, 2, 3]
10+
# Output: [2, 3]
11+
# Explanation: 2 and 3 occur more than once in the given array.
12+
# Input: arr[] = [3, 1, 2]
13+
# Output: []
14+
# Explanation: There is no repeating element in the array, so the output is empty.
15+
# Constraints:
16+
# 1 ≤ n ≤ 106
17+
# 1 ≤ arr[i] ≤ n
18+
19+
20+
from collections import Counter
21+
class Solution:
22+
def findDuplicates(self, arr):
23+
# code here
24+
cmt1 = Counter(arr)
25+
res = [num for num, freq in cmt1.items() if freq > 1]
26+
return res

0 commit comments

Comments
 (0)