Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

Click here to see the full article post

you could improve peekMax from logn to constant time.

How do you handle duplicates for approach 2?

@zws1818918 Can you please share some idea about the improvement?

Solution #1 can't be linear in the worst case: pushing N/2 numbers in descending order and then popMax N/2 times. Since the solution enumerates the whole stack on every popMax, overall complexity is O(n^2)

Thanks for sharing!

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.