Solution fails to pass one test with large inputs?

There is no need to sort the array, you can do the problem in O(n) times

function birthdayCakeCandles(arr, n) {
    var total = 0;
    var len = arr.length;
    for (var i = 0; i < len; i++) {
        if (ar[i] === n) 
            total++;
    }
    return total;

Browse More Popular Posts

Leave a Comment