Sunday, 2 April 2017

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

sort(array.begin(),array.end()); //an array start address index to end address index

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.

Submit your solution here:- Click here

Tip:- Before copy the solution I recommended please read this full article, this will help you to build your own logic.


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:-

Hacker Rank Solution For " Birthday Cake Candles " in C++

You May Like This:-










10. C Program For Find A Grade Of Given Marks Using Switch Case

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment