Saturday, October 29, 2022

Birthday Cake Candles Problem(Hacker Rank)

 You are in charge of the cake for a child's birthday. You have decided the cake will have one candle for each year of their total age. They will only be able to blow out the tallest of the candles. Count how many candles are tallest.

Example

The maximum height candles are  units high. There are  of them, so return .


SOLUTION:

    public static int birthdayCakeCandles(List<int> candles)
    {
       int max = candles.Max();
       int result = candles.Count(x=>x==max);
       return result;
    }

Description
  1. Find the tallest candle.
  2. Count the number of tallest candles using linq.
  3. return result.


No comments:

Post a Comment

JavaScript Functions as JavaScript Variables

In Javascript instead of declaring and executing a function in two different steps. for example step 1 -  function add(a,b){return a+b;} ste...