This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
DSA/midterm_prep/207.py

34 lines
533 B
Python
Raw Normal View History

2019-03-28 10:45:47 +00:00
#!/usr/bin/env python3
import sys
def better_algo_X(A):
B = A.copy()
B.sort() # assume mergesort for theta (n * log(n))
x = 1
y = B[0]
k = 1
print(B)
for k in range(1, len(B)):
if B[k] == B[k - 1]:
k = k + 1
else:
if k > x:
y = B[k - 1]
x = k
k = 1
return y
A = []
for line in sys.stdin:
line = line.strip()
if line == '' or line == '\n':
break
A.append(int(line))
print(better_algo_X(A))