Skip to content

Commit 887befd

Browse files
committed
Majority Element - More Than n/3
1 parent c23c00f commit 887befd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Majority Element - More Than n/3
2+
def findMajority(arr):
3+
data = {}
4+
n = len(arr)
5+
t = n // 3
6+
majority = []
7+
for i in arr:
8+
if i in data:
9+
data[i] += 1
10+
else:
11+
data[i] = 1
12+
for key in data:
13+
if data[key] > t:
14+
majority.append(key)
15+
return sorted(majority)
16+
17+
18+
# T.C = O(n)
19+
# S.C = O(n)

0 commit comments

Comments
 (0)