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.

While this works, you loop through the complete collection of values 3 times. First while reading it in the scanner. Second while scanning for the max value in the collection after reading it in and third to count the number of times it was found.

I'm not too familiar with the BigO notation, so an honest question how does it become n+n+n shouldn't it be 3n rather as you are doing full loops over all elements?

## Birthday Cake Candles

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

Any problem with Java @abhishek106

While this works, you loop through the complete collection of values 3 times. First while reading it in the scanner. Second while scanning for the max value in the collection after reading it in and third to count the number of times it was found.

anyway the time complexity is O(n+n+n) = O(n)

I'm not too familiar with the BigO notation, so an honest question how does it become n+n+n shouldn't it be 3n rather as you are doing full loops over all elements?

In BigOh notation, I believe they drop the constants in front of n because exponents matter so much more that the constants are negligible.