Problem 1081 · Medium
Keep a monotonic stack of letters, popping a larger letter only when it appears again later.
Open the interactive visualisation