Birthday Cake Candles hackerrank solution java
Problem : Find maximum numbers of values present in array with highest array value
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static int birthdayCakeCandles(int n, int[] ar,int max) {
int count=0;
for(int c:ar)
{
if(c==max)
count++;
}
return count;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] ar = new int[n];
int max=Integer.MIN_VALUE;
for(int ar_i = 0; ar_i < n; ar_i++){
ar[ar_i] = in.nextInt();
if(ar[ar_i]>max)
max=ar[ar_i];
}
int result = birthdayCakeCandles(n, ar,max);
System.out.println(result);
}
}
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static int birthdayCakeCandles(int n, int[] ar,int max) {
int count=0;
for(int c:ar)
{
if(c==max)
count++;
}
return count;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] ar = new int[n];
int max=Integer.MIN_VALUE;
for(int ar_i = 0; ar_i < n; ar_i++){
ar[ar_i] = in.nextInt();
if(ar[ar_i]>max)
max=ar[ar_i];
}
int result = birthdayCakeCandles(n, ar,max);
System.out.println(result);
}
}
0 Comments:
Post a Comment