javascript - Solution fails to pass one test with large inputs? -
function birthdaycakecandles(n, ar) { // complete function ar.sort(); var biggestno = ar[(ar.length - 1)]; var total = 0; (var = 0; < ar.length; i++) { if (ar[i] === biggestno) total++; } return total; }
here's problem - https://www.hackerrank.com/challenges/birthday-cake-candles/problem
there no need sort array, can problem in o(n) times
function birthdaycakecandles(arr, n) { var total = 0; var len = arr.length; (var = 0; < len; i++) { if (ar[i] === n) total++; } return total;
Comments
Post a Comment