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 use quicksort u already have O(nlogn) which is worse than just iteratring through the array and saving the highest value and then just iterate a second time incrementing a counter everytime the value is similar to the saaved one. then complexity is O(2n) = O(n).
With n = 100 you would have ~ 600 steps(n*logn = 100 * 6 = 600) with your solution and just 200 steps with mine

Yes for this one it looks easy to use initial ... I was wondering about using the bubble sort for all kinds these qs..
Thank you for this code Its great

Bubblesort i believe averages O(n^2), so i believe quicksort will generally be faster. For most of the questions on here its likely not worth using a sort as the benefits wouldn't be seen on only one use of the data. I think Linq is probably a better choice then a sort in this scenario but im not 100% sure.

## Birthday Cake Candles

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

if you use quicksort u already have O(nlogn) which is worse than just iteratring through the array and saving the highest value and then just iterate a second time incrementing a counter everytime the value is similar to the saaved one. then complexity is O(2n) = O(n). With n = 100 you would have ~ 600 steps(n*logn = 100 * 6 = 600) with your solution and just 200 steps with mine

Wouldn't it be faster to maintain your count in the initial iteration?

Yes for this one it looks easy to use initial ... I was wondering about using the bubble sort for all kinds these qs..

Thank you for this code Its great

Bubblesort i believe averages O(n^2), so i believe quicksort will generally be faster. For most of the questions on here its likely not worth using a sort as the benefits wouldn't be seen on only one use of the data. I think Linq is probably a better choice then a sort in this scenario but im not 100% sure.

yeah I agree with that.. Thanks bro.. :)