Birthday Cake Candles

  • + 0 comments

    Golang

    func birthdayCakeCandles(candles []int32) int32 {
        // Write your code here
        n := len(candles)
        if n <=0 {
            return 0
        }
        
        maxCount :=1
        maxValue := candles[0]
        for i:=1;i<n;i++ {
            if candles[i]>maxValue {
                // reset the counter and update the new max value
                maxCount = 1
                maxValue = candles[i]
            } else if candles[i] == maxValue {
                maxCount++
            }
        }
        return int32(maxCount)
    }