# Hacker Rank solution for Birthday Cake Candles In C++

Problem:- Hacker Rank Solution Program In C++ For " Birthday Cake Candles " or Hacker Rank Solution Program In C++ For Birthday Cake Candles or Birthday Cake Candles solution hacker rank or Hacker rank solution for c++ domain or Hacker rank solution for Birthday Cake Candles subdomain or Birthday Cake Candles solution in c++ of hacker rank.

Check This- Hacker rank Solution for C++ Sub Domain Introduction, Classes, STL, Inheritance.

Logic:- Birthday Cake Candles is very simple I am going to explain this problem in simple steps. So basically in this problem, first we have to find the largest number than we compare how many numbers are greater or equal to our largest number that's it. If you don't get the solution don't worry below is the step by step explanation of the problem Birthday Cake Candles.

Explanation:- First we have to sort the array for sorting we are using vector array and sort function for minimizing the time or we can do the same thing by using sorting technique like Bubble sort, Insertion sort, Selection sort

Sorting of an Array

Now the next step is to compare how many elements in the array is equal to the largest element in an array. Before that put the largest element of an array to the temp variable and if the elements of an array are equal to the largest element of an array than respectfully increase the counter by 1.

temp=array[n-1];

for(i=0; i<n; i++)
{
if(temp==array[i])
count++;
}

Last step is to print the counter this is the answer of the problem Birthday Cake Candles

cout<<count;

Hence we get our answer but remember in this solution in a comment some statement is written these statement for checking is our sorting is working fine or not.

Solution:-

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
int n,temp=0,count=0,i;
cin>>n;

vector<int> array(n);

for(i=0; i<n;i++)
{
cin>>array[i];
}

sort(array.begin(),array.end());

temp=array[n-1];

/*for(int i=0; i<n;i++)
cout<<c[i];
*/

for(i=0; i<n; i++)
{
if(temp==array[i])
count++;
}

cout<<count;

return 0;
}

Output:-

You May Like This:-