Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Use a monotonic increasing stack of digits. While the current digit is smaller than stack top and removals remain, pop larger digits to reduce the number lexicographically. Remove any extra digits from the end, then strip leading zeros.
Earlier digits have higher place value impact. Greedily removing larger preceding digits when a smaller digit appears yields the smallest final number.
Updated Feb 2026