We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
Cookie support is required to access HackerRank
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 →
C# or csharp solution: public static int birthdayCakeCandles(List candles) { int max = candles.Max(); int count = 0;
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.