We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Migratory Birds
Migratory Birds
Sort by
recency
|
3621 Discussions
|
Please Login in order to post a comment
Why can't I use statistics.mode(arr) to solve it.
Here is a python solution with O(n + k) time and O(k) space:
Here is problem solution in Python, Java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-migratory-birds-problem-solution.html
n = int(input()) arr = list(map(int(input().strip().split(" ")))) d={} for i in arr: d[i] = arr.count(i)
maxfreq = max(d.values())
result = 10000 for i in d: if d[i] == maxfreq: result = min(i,result) print(result)