Smallest Number After Removing k Digits
Updated
Problem statement
You are given a non-negative whole number as a string num and an integer k. Remove exactly k digits from num, keeping the other digits in their original order, so that the number left is as small as possible. Return that number as a string.
Drop any leading zeros from the result. If no digits are left, or only zeros are left, return "0".
Function
smallestAfterRemoval(num: String, k: int) → StringExamples
Example 1
num = "7364019"k = 3return = "3019"Remove 7, then 6 and 4 (each is larger than the digit after it) to keep 3, 0, 1, 9. The kept digits read 3019, which is the smallest result.
Example 2
num = "50082"k = 1return = "82"Removing the leading 5 leaves 0082. Leading zeros are dropped, so the answer is 82.
Example 3
num = "468"k = 3return = "0"All three digits are removed. Nothing is left, so the answer is 0.
Constraints
1 <= num.length <= 5000numconsists of digits only and has no leading zeros, except when it is"0"itself.0 <= k <= num.length
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Remove K DigitsProcol · PHONE SCREEN
- Minimum Removal for Balanced ParenthesesMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Largest Number After Removing K DigitsGoogle · PHONE SCREENGoogle interview questions
- Minimum Remove to Make Valid ParenthesesBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Remove Duplicate Letters for the Largest ResultAmazon · PHONE SCREEN
- Lexicographically Largest Distinct-Letter SubsequenceNavan · PHONE SCREENNavan interview questions
- Substring RemovalJP Morgan Chase · OAJP Morgan Chase interview questions
- Remove K DigitsThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
- Remove K DigitsMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
- Modify the StringYahoo · OAYahoo interview questions
Interview reports that mention this question
Adobe interview experiences
- Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
- Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
- Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
- Adobe New Grad MTS Interview Questions: 7 Experiences
- Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)