You are viewing a single comment's thread. Return to all comments →
I did it similarly to you at first but then I tried to optimize it from O(2n) (for loop and list.index()) to O(n) and came up with this:
def migratoryBirds(n, ar): ids = [0] * 5 maxN = 0 id = 1 for i in range(n): ids[ar[i] - 1] += 1 if(ids[ar[i] - 1] > maxN): maxN = ids[ar[i] - 1] id = ar[i] elif(ids[ar[i] - 1] == maxN and ar[i] < id): id = ar[i] return id
Seems like cookies are disabled on this browser, please enable them to open this website
Migratory Birds
You are viewing a single comment's thread. Return to all comments →
I did it similarly to you at first but then I tried to optimize it from O(2n) (for loop and list.index()) to O(n) and came up with this: