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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -