You are viewing a single comment's thread. Return to all comments →
This is wrong if you do an interview. They most likely want to see a solution which is O(n) and yours is O(n^2).
This is mine, which is O(n):
def birthdayCakeCandles(ar): max_h = ar[0] max_n = 1 for c in ar[1:]: if c > max_h: max_h = c max_n = 1 elif c == max_h: max_n += 1 print(max_n)
Seems like cookies are disabled on this browser, please enable them to open this website
Birthday Cake Candles
You are viewing a single comment's thread. Return to all comments →
This is wrong if you do an interview. They most likely want to see a solution which is O(n) and yours is O(n^2).
This is mine, which is O(n):