Birthday Cake Candles

  • + 4 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)