The security office at a research campus scans every employee badge as a string of digits, each digit from 1 to 9 (the scanner never produces a 0). A known hardware fault means exactly one keystroke of a specific flagged digit must be struck from the scanned code before the turnstile will accept it — the office may choose which occurrence of that digit to strike, and the remaining digits keep their original left-to-right order to form the accepted code. Since striking one digit always leaves a code with exactly one fewer digit no matter which occurrence is chosen, the accepted code with the largest possible numeric value is simply the one that compares largest as a string of that same length. Determine the largest accepted code the office can produce.
number of digits, each in the range 1-9.digit (also in the range 1-9) that occurs at least once in number.Print the resulting string after striking exactly one occurrence of digit from number, chosen so the remaining string is as large as possible.
number <= 100number is a digit from 1 to 9 (never 0)digit is a single character from 1 to 9 and appears at least once in numberExample 1
Input
5273 2
Expected
573
Explanation
The flagged digit '2' occurs only once, at the second position of "5273". Striking that single occurrence is the only option, leaving "573".
Example 2
Input
4353 3
Expected
453
Explanation
The flagged digit '3' occurs at two positions in "4353": right after the leading '4', and at the very end. Striking the first '3' (which is followed by a larger digit, '5') leaves "453"; striking the second '3' leaves "435". "453" is larger, so that is the answer.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →