HackerRank Birthday Cake Candles Problem Solution in C
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n; scanf("%d",&n); long int arr[n],i,temp,j=0; for(i=0;i<n;i++) { scanf("%ld",&arr[i]); } temp=arr[0]; for(i=0;i<n-1;i++) { if(temp<arr[i+1]) temp=arr[i+1]; } for(i=0;i<n;i++) { if(arr[i]==temp) j++; } printf("%ld",j); return 0; }
HackerRank Birthday Cake Candles Problem Solution in JavaScript
function countInArray(arr, item) { var count = 0; var len = arr.length; for (var i = 0; i < len; i++) { if (arr[i] === item) { count++; } } return count; } function processData(input) { heights = input.split("\n")[1].split(" "); heights = heights.map(function(item) { return parseInt(item, 10); }); console.log(countInArray(heights, Math.max.apply(null, heights))); } process.stdin.resume(); process.stdin.setEncoding("ascii"); _input = ""; process.stdin.on("data", function (input) { _input += input; }); process.stdin.on("end", function () { processData(_input); });
HackerRank Birthday Cake Candles Problem Solution in Python
n=int(input()) s=[] s[0:]=map(int,input().split()) m=max(s) print(s.count(m))
0 Comments