Remove Digit From Number to Maximize Result

You are given a string number representing a positive integer and a character digit.

Return the resulting string after removing exactly one occurrence of digit from number such that the value of the resulting string in decimal form is maximized. The test cases are generated such that digit occurs at least once in number.

Example 1
Inputnumber = "123", digit = "3"
Output"12"
There is only one '3' in "123", so after removing '3', the result is "12".
Example 2
Inputnumber = "1231", digit = "1"
Output"231"
Removing the first '1' gives "231" and removing the second '1' gives "123"; since 231 > 123, return "231".

Constraints

  • 2 <= number.length <= 100
  • number consists of digits from '1' to '9'.
  • digit is a digit from '1' to '9'.
  • digit occurs at least once in number.

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate