← Discussions on Next Greater Element (Circular)
P poojamenon
10 Jun 2026, 17:55

Asked in my Freshworks OA last week.

A monotonic stack is the trick: pop while the current element breaks the order, and the popped elements have just found their answer.

2 replies

kavyanai4 4 months, 1 week ago

You can avoid the extra array and do it in O(1) space.

cverma 4 months ago

For the TLE: you are rebuilding the list inside the loop, move it outside.

Sign in to reply.