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.
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.
You can avoid the extra array and do it in O(1) space.
For the TLE: you are rebuilding the list inside the loop, move it outside.
Sign in to reply.