Ctrl K

Strike Out a Digit for the Maximum

Easy
You are given a positive number as a string num and a digit digit that occurs in num at least once. Strike out exactly one occurrence of digit from num so that the remaining number is as large as possible. Return that number as a string.
Example 1
num="4747", digit="4" → '747'

Dropping the first 4 gives 747, dropping the second gives 477. The larger one is 747.

Example 2
num="92", digit="2" → '9'

There is only one 2, so 9 remains.

Example 3
num="3633", digit="3" → '633'
Constraints
  • 2 ≤ len(num) ≤ 100
  • num consists of digits from 1 to 9
  • digit is a digit from 1 to 9
  • digit occurs in num
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPattern Woven Several Times HardShortest String Holding Three Words MediumErase Digits Until It Divides by 25 MediumPalindrome From Letter Tiles EasyPalindrome With One Eraser Stroke Easy
loading Python…
Input
num="4747", digit="4"
Expected
'747'

Run checks the first 3 tests in your browser. Submit checks all 99 tests on the server, hidden ones included.