You are in charge of the cake for your niece's birthday and have decided the cake will have one candle for each year of her total age. When she blows out the candles, she’ll only be able to blow out the tallest ones. Your task is to find out how many candles she can successfully blow out.
For example, if your niece is turning  years old, and the cake will have  candles of height , she will be able to blow out  candles successfully, since the tallest candles are of height  and there are  such candles.

Solution in C# -

class Solution {
    static int birthdayCakeCandles(int[] ar) {
        Array.Sort(ar);
        int count = 0;
        for(int i=0; i<ar.Length; i++)
        {
            if(ar[ar.Length-1] == ar[i])
            count++;          
        }
        return count;
    }
    static void Main(string[] args) {
        TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
      int arCount = Convert.ToInt32(Console.ReadLine());
        int[] ar = Array.ConvertAll(Console.ReadLine().Split(' '), arTemp => Convert.ToInt32(arTemp));
        int result = birthdayCakeCandles(ar);
        textWriter.WriteLine(result);
        textWriter.Flush();
        textWriter.Close();
    }
}

Post a Comment

Previous Post Next Post