We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

If you dont mind can you please provide a feedback on my video by commenting or liking & disliking. It will help me and others too to find the solution over internet.

If you dont mind can you please provide a feedback on my video by commenting or liking & disliking. It will help me and others too to find the solution over internet.

Count should be initialized to 1 as there is atleast one tallest. In this case, if the frequency of largest element is 0, count would return 0 which is an error

## Birthday Cake Candles

You are viewing a single comment's thread. Return to all comments →

I tried this

It is failing the test case

100000 followed by 100000 times 9999999 (as height of candles(array values)).

Pass all Testcases..

Try This

static int birthdayCakeCandles(int[] ar) {

Hi,

Your solution is good but it will take O(nlogn) time due to sorting which can be optimized to O(n)

Here is the video explanation of my solution in O(n) time -

https://youtu.be/1gxFE9EfanE

Any comments and feedback will be appreciated.

Thanks for that. I worked out a solution where I do it in O(n) time. Posted on your video.

most welcome. :)

If you dont mind can you please provide a feedback on my video by commenting or liking & disliking. It will help me and others too to find the solution over internet.

thanks

most welcome. :)

If you dont mind can you please provide a feedback on my video by commenting or liking & disliking. It will help me and others too to find the solution over internet.

need to add one more check in while condition for all the array elements with same value

while ( i > -1 && a[i--] == tallest ) { count++; }

Count should be initialized to 1 as there is atleast one tallest. In this case, if the frequency of largest element is 0, count would return 0 which is an error

Mine fails on that too. ar.sort(); ar.reverse(); let m = 0; let k = ar[0]; while (parseInt(ar[m]) === parseInt(k)){ m++; } return m; }

Hi,

Here is the video explanation of my solution in O(n) time -

https://youtu.be/1gxFE9EfanE

Any comments and feedback will be appreciated.

while (

i>-1&&a[i--] == tallest) { count++; }You just forgot to check whether the index i is within the bounds.

Same issue with that case for me as well in javascript

ar_count = int(raw_input())

ar = list(map(int, raw_input().strip().split()))

max_height = max(ar)

print(ar_count - len(list(filter(lambda x: x!=max_height,ar))))) Try this! It worked when I split max into a different line.