Birthday Cake Candles

  • + 0 comments

    C# or csharp solution: public static int birthdayCakeCandles(List candles) { int max = candles.Max(); int count = 0;

        foreach(int i in candles)
        {
            if (i == max)
                count++;
        }
    
        return count;
    }
    
    Now I'm just getting into Big O notation, so if any other commenters could help me figure out the Big O of this algorithm, it would be greatly appreciated.
    

    I'm thinking it would be O(2n) - since candles.Max() presumably is looping through the array once and then my foreach loop will iterate through the array once more.