HackerRank has a challenge for calculating which birthday candles get blown out.
My C# solution looked particularly elegant to me, so I thought I'd show it here:
public static int birthdayCakeCandles(List<int> candles)
{
var maxHeight = candles.Max();
var numOfCandles = candles.Count(c => c == maxHeight);
return numOfCandles;
}
Top comments (3)
Hey @tandu-dev, nice solution, thanks for sharing!
I wonder if using the GroupBy would have save some iterations here
A dictionary might also be a good fit for such a problem!
That's definitely a workable solution? Could you go into it a little more? I'm familiar with the => notation for Linq, but haven't seen it used with the method this way. Is this more functional programming?
Kind of, those are just syntactic sugar, it is a body expression 😄