Approach hintTry it first, then revealHide
Keep the digits on a stack that is non-decreasing from bottom to top, popping a larger digit whenever a smaller one arrives and removals remain. Drop any leftover removals from the end and strip leading zeros.