Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank, Algorithm Solutions of Problem Solving Section in Java. At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.
In this post, you will find the solution for Birthday Cake Candles in Java-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.
Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.
Introduction To Algorithm
The word Algorithm means “a process or set of rules to be followed in calculations or other problem-solving operations”. Therefore Algorithm refers to a set of rules/instructions that step-by-step define how a work is to be executed upon in order to get the expected results.
Advantages of Algorithms:
- It is easy to understand.
- Algorithm is a step-wise representation of a solution to a given problem.
- In Algorithm the problem is broken down into smaller pieces or steps hence, it is easier for the programmer to convert it into an actual program.
Link for the Problem – Birthday Cake Candles – Hacker Rank Solution
Birthday Cake Candles – Hacker Rank Solution
Problem:
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 .
Function Description
Complete the function birthdayCakeCandles
in the editor below.
birthdayCakeCandles has the following parameter(s):
- int candles[n]: the candle heights
Returns
- int: the number of candles that are tallest
Input Format
The first line contains a single integer, , the size of .
The second line contains space-separated integers, where each integer describes the height of .
Constraints
Sample Input 0
4 3 2 1 3
Sample Output 0
2
Explanation 0
Candle heights are . The tallest candles are units, and there are of them.
Birthday Cake Candles – Hacker Rank Solution
import java.util.Scanner; /** * @author Techno-RJ * */ public class BirthdayCakeCandles { static int birthdayCakeCandles(int[] ar) { int maxCandleHeight = Integer.MIN_VALUE; int maxCandleFreqCount = 0; for (int i = 0; i < ar.length; i++) { if (ar[i] == maxCandleHeight) { maxCandleFreqCount++; } if (ar[i] > maxCandleHeight) { maxCandleHeight = ar[i]; maxCandleFreqCount = 1; } } return maxCandleFreqCount; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int M = sc.nextInt(); int a[] = new int[M]; for (int i = 0; i < M; i++) { a[i] = sc.nextInt(); } System.out.println(birthdayCakeCandles(a)); sc.close(); } }
cheap generic tadalafil tadalafil us pills for erection
order cefadroxil 500mg for sale buy proscar 5mg online propecia for sale
order fluconazole 100mg without prescription purchase ampicillin for sale order cipro 500mg generic
buy estradiol online cheap minipress canada prazosin 2mg pills
cleocin for sale online buy fildena sale erection pills viagra online
oral avana 200mg order tadacip 20mg for sale order diclofenac 50mg sale
tamoxifen 20mg us order tamoxifen 20mg generic order cefuroxime 500mg pill
bimatoprost uk purchase bimatoprost sale purchase desyrel generic
buy amoxicillin generic generic arimidex purchase clarithromycin online cheap
order sildenafil pill sildenafil 50mg tablet purchase sildalis pill
how to get clonidine without a prescription antivert 25mg cost buy tiotropium bromide for sale
minocycline 50mg uk actos 15mg cheap buy pioglitazone 15mg sale
purchase accutane without prescription order zithromax pills order zithromax generic
order leflunomide 10mg for sale buy sulfasalazine 500 mg online azulfidine 500 mg tablet
azipro 500mg cheap neurontin 600mg ca cheap gabapentin sale
order generic cialis 20mg order tadalafil 40mg sale tadalafil 10mg generic
cost furosemide 40mg buy lasix 40mg albuterol buy online
ivermectin 3mg tablets order deltasone 10mg generic buy prednisone 10mg for sale
vardenafil online buy order tizanidine 2mg sale order plaquenil
buy levitra 10mg sale buy vardenafil tablets buy cheap generic plaquenil
buy generic asacol online buy asacol 400mg brand avapro 300mg
buy benicar pill buy olmesartan pills order depakote sale