Skip to content
We areTOP 1%

Remove K Digits

MediumLeetCodeMonotonic Stack
Solve on LeetCode(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Approach hintTry it first, then reveal

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.

More in Monotonic Stack

Monotonic Stack questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Next Greater Element ILeetCodeEasy Solve Next Greater Element I on LeetCode (opens in a new tab)
2Bad PricesCodeforcesEasy 1100Solve Bad Prices on Codeforces (opens in a new tab)
3Minimum NotationCodeforcesEasy 1200Solve Minimum Notation on Codeforces (opens in a new tab)
4Next Greater Element IILeetCodeMedium Solve Next Greater Element II on LeetCode (opens in a new tab)
5Daily TemperaturesLeetCodeMedium Solve Daily Temperatures on LeetCode (opens in a new tab)
6Online Stock SpanLeetCodeMedium Solve Online Stock Span on LeetCode (opens in a new tab)
7Remove K DigitsLeetCodeMedium Solve Remove K Digits on LeetCode (opens in a new tab)
8Largest SubsequenceCodeforcesMedium 1400Solve Largest Subsequence on Codeforces (opens in a new tab)
9Sum of Subarray MinimumsLeetCodeMedium Solve Sum of Subarray Minimums on LeetCode (opens in a new tab)
10Skyscrapers (easy version)CodeforcesMedium 1500Solve Skyscrapers (easy version) on Codeforces (opens in a new tab)
11Largest Rectangle in HistogramLeetCodeHard Solve Largest Rectangle in Histogram on LeetCode (opens in a new tab)
12Maximal RectangleLeetCodeHard Solve Maximal Rectangle on LeetCode (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account