Remove K Digits
Reported by candidates from DE Shaw's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The DE Shaw OA reported in September 2026 hands you "1432219", k = 3, and expects "1219". That's Remove K Digits, and it's a monotonic stack problem wearing a string costume. You're picking which digits to delete so the leftover number is as small as possible, with order locked. If you've seen the stack trick, it's ten minutes of work. If you haven't, brute force dies on a 10^5 length input. StealthCoder is the safety net running invisibly during the live OA if your mind goes blank on the greedy part. Here's the pattern so you don't need it.
The problem
You are given a string num that represents a non-negative integer, and an integer k. Remove exactly k digits from num so the remaining digits stay in their original relative order and form the smallest possible integer. Return that integer as a string. Do not keep leading zeros, except for the integer 0 itself. Function removeKdigits(num: String, k: int) → String Examples Example 1 num = "1432219" k = 3 return = "1219" Removing the digits 4, 3, and 2 from 1432219 leaves 1219, which is the smallest remaining integer. Example 2 num = "10200" k = 1 return = "200" Removing the leading 1 leaves 0200, which becomes 200 after leading zeros are stripped. Example 3 num = "10" k = 2 return = "0" Every digit is removed, so the result is 0. Constraints 1 <= num.length <= 10^5. 1 <= k <= num.length. num consists of digits only. num has no leading zeros except when num is "0".
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is greedy with a monotonic increasing stack. Walk through num left to right. While the stack top is larger than the current digit and you still have removals left, pop it. Then push the current digit. A bigger digit sitting before a smaller one is always worth deleting, because the earlier position matters most. After the loop, if k is still above zero, pop from the end, since the stack is already non-decreasing and the tail is the largest. Then strip leading zeros and return "0" if nothing is left. The pitfalls are exactly those last steps: forgetting leftover k (like "10" with k = 2, or "111" with k = 1), and forgetting leading zeros as in "10200". Don't build strings with repeated concatenation or you'll blow the 10^5 bound. Use a list and join once. If the stack logic slips under pressure, StealthCoder is the hedge during the live OA.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Remove K Digits cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as remove k digits. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass DE Shaw's OA.
DE Shaw reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Remove K Digits FAQ
What's the trick to Remove K Digits?+
Use a monotonic increasing stack. For each digit, pop the stack while the top is greater than the current digit and k is above zero, then push. A larger digit ahead of a smaller one always hurts the number, so you delete it right away. That greedy choice is provably optimal.
How hard is this problem really for the DE Shaw OA?+
It's medium, but the greedy insight trips people up. Once you know the stack approach, the code is short. The difficulty lives in edge cases: leftover k, leading zeros, and an empty result. Those are where most failed submissions break.
What edge cases should I test before submitting?+
Test "10" with k = 2 (answer "0"), "10200" with k = 1 (answer "200"), and a strictly increasing string like "12345" with k = 2, where nothing pops mid-loop and you trim from the end. Also try all equal digits like "1111".
What's the time complexity I should aim for?+
O(n) time and O(n) space. Each digit is pushed once and popped at most once. With length up to 10^5, anything quadratic, like trying every removal combination or repeatedly rescanning the string, will time out.
How do I prepare for this in 48 hours?+
Write the stack solution from memory twice. Then trace "1432219" with k = 3 by hand until the pops feel obvious. Spend remaining time on the finish steps: trim leftover k from the tail, strip leading zeros, and return "0" for empty. That covers nearly every variant.