Epic OA Interview Question: Broken Labeler

15 Views
No Comments

You need to label a large number of files from 1 to N, but one number key on your labeler is broken. Write a program that prompts the user for N and the broken number key, then prints the highest possible file number the user can print on the labeler.

For example, if the user enters N = 56781232 and the broken number key is 2, then the highest possible file number is 56781199.

The core idea is to start from N and search downward until you find the largest number that does not contain the broken digit. A simple digit-check function can inspect each candidate by repeatedly taking modulo 10 and dividing by 10. As soon as a valid number is found, it is the answer. This problem mainly tests number-digit handling and a straightforward greedy scan.

END
 0