Remove one digit to get the largest number
Given a number (as text) and a digit d that appears in it, remove exactly one occurrence of d so that the remaining number is as large as possible. Print it.
Reported in: Infosys (DSE / SP, 2023–26) (memory-based)
Input
First line: the number. Second line: the digit d.
Output
The largest number possible.
Constraints
2 ≤ length ≤ 100; d appears at least once.
Example 1
Input:
1231
1
Output:
231Example 2
Input:
551
5
Output:
51Hint: Remove the first d that is followed by a bigger digit; if there is none, remove the last d. (Trying every occurrence also works for short numbers.)