-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay_50.py
More file actions
34 lines (25 loc) · 785 Bytes
/
Day_50.py
File metadata and controls
34 lines (25 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
DAY 50 : Print Non-Repeated Elements.
https://www.geeksforgeeks.org/non-repeating-element/
QUESTION : Hashing is very useful to keep track of the frequency of the elements in a list.
You are given an array of integers. You need to print the non-repeated elements as they appear
in the array.
Expected Time Complexity : O(N)
Expected Auxilliary Space : O(N)
Constraints:
1 ≤ N ≤ 10^3
1 ≤ arr[i] ≤ 10^7
"""
def printNonRepeated(arr,n):
count = {}
dist = []
for i in range(n):
if arr[i] in count.keys():
count[arr[i]]+=1
else:
count[arr[i]] = 1
for i in arr:
if count[i] == 1:
dist.append(i)
return dist
print(printNonRepeated([10,20,40,30,10], 5))