FastPrepRemove K Digits for the Smallest Number
Problems/Remove K Digits for the Smallest Number

Remove K Digits for the Smallest Number

Nutanix logoNutanix● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A fall-2018 report covers a Nutanix intern online assessment with two questions in about 90 minutes. The report calls the second question an unmodified well-known problem and identifies it only by a disguised number. We read it as Remove K Digits.

The report gives no statement, limits or examples. The rules here are ours, taken from the usual form of that problem. Delete exactly k digits and keep the rest in order. Write the result without leading zeros, and return "0" when nothing is left. The limits (up to 10^4 digits) and the examples are also ours.

Our version is about 80% the same as the reported question.

You are given a non-negative integer as a string num and an integer k.

Delete exactly k digits from num. The digits you keep stay in their original order. Return the smallest number you can get, as a string.

Write the result without leading zeros. If no digits are left, or only zeros are left, return "0".

Function

removeKDigits(num: String, k: int) → String

Examples

Example 1

num = "4205839"k = 3return = "539"

Three digits must go, so four stay. Deleting 4 and 2 brings the 0 to the front, and a leading zero is not written, so the result has at most three digits. That leaves 0 5 8 3 9 with one more digit to delete. Deleting 8, the first digit that is bigger than the digit after it, gives 0539, written "539".

Example 2

num = "30200"k = 1return = "200"

Deleting the 3 leaves 0200, which is written "200". Deleting any other digit keeps the 3 in front and leaves a four-digit number, which is bigger.

Example 3

num = "71"k = 2return = "0"

Both digits are deleted. Nothing is left, so the answer is "0".

Constraints

  • 1 <= k <= num.length <= 10^4
  • num consists only of the digits 0 to 9.
  • num has no leading zeros, except that num may be exactly "0".

More Nutanix Online Assessment questions

  • Good SubsequencesOA · Seen Jul 2026
  • Min Cost to Connect All PointsOA · Seen Jun 2026
  • Digit Changes for a Multiple of 9OA · Seen Aug 2025
  • Gas Station Loop StartOA · Seen Aug 2025
  • Number of Players (for MTS2)OA · Seen Oct 2024
  • Work Schedules (for MTS2)OA · Seen Oct 2024
  • Minimum Operations to Convert ArrayOA · Seen Apr 2024
  • No Adjacent CharactersOA · Seen Apr 2024
  • Build a BST From a ListOA · Seen Nov 2022
  • Delete Even-Valued Nodes From a Linked ListOA · Seen Nov 2022

Similar questions at other companies

  • Substring RemovalJP Morgan Chase · OAJP Morgan Chase interview questions
  • Modify the StringYahoo · OAYahoo interview questions
  • Lexicographically Minimum Stack EncryptionRippling · OARippling interview questions
  • Shortest String After Erasing Equal PairsMarshall Wace · OAMarshall Wace interview questions
  • Minimum Insertions to Balance a Parentheses StringIBM · OAIBM interview questions
  • Largest SubsequencesCashfree Payments · OA
  • Good Binary StringsBNP Paribas · OA
  • Remove K DigitsProcol · PHONE SCREEN
  • Remove K DigitsThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
  • Remove K DigitsAmazon · ONSITE INTERVIEW

Interview reports that mention this question

  • Nutanix SWE Intern OA Questions: 16 Experiences (Part 2 of 3)

Nutanix interview experiences

  • Nutanix SWE Intern Phone Screens: 20 Experiences (Part 3 of 3)
  • Nutanix U.S. SWE Intern Interviews: 54 Experiences (Part 1 of 3)
  • Nutanix SWE OA and Interviews, Level Not Reported: 9 Experiences
  • Nutanix Intern Debugging Round and Interviews: 25 Experiences
All Nutanix interview questionsSee Nutanix hiring insights
Saved
class Solution {
    public String removeKDigits(String num, int k) {
        // Write your code here.
    }
}
Checking account…