3

# Closest greater

Difficulty: EASY
Avg. time to solve
15 min
Success Rate
85%

Problem Statement
Suggest Edit

#### Given a positive integer ‘N’, you have to find the closest number to 'N' which is greater than ‘N’, and has at most one non-zero digit. In other words, you have to find a number ‘K’ such that:

``````1. 'K' should be strictly greater than 'N'.

2. 'K' should contain at most 1 non-zero digit.

3. Difference between 'N' and 'K' should be minimum.
``````
##### For eg.
``````Consider the number 546. The closest number greater than 546 that contains at most 1 non-zero digit is 600.
``````
##### Input format:
``````The first line of input contains an integer ‘T’ denoting the number of test cases.

The first and the only line of each test case contains a positive integer ‘N’.
``````
##### Output Format
``````For each test case, print a single line containing a single integer denoting the number 'K' as described above in a single line.

The output for each test case will be printed in a separate line.
``````
##### Note
``````You don’t have to print anything, it has already been taken care of. Just implement the given function.
``````
##### Constraints:
``````1 <= T <= 1000
1 <= N <= 10 ^ 18

Time limit: 1 second
``````
##### Sample Input 1:
``````2
13
100
``````
##### Sample Output 1:
``````20
200
``````
##### Explanation of sample input 1:
``````Test case 1:
We can see that the numbers greater than 13, having at most one non-zero digit are 20, 30, 40, 50... so on. The answer is 20 because it is the closest to 13.

Test case 2:
Clearly, the first greater number than 100 containing at most one non-zero digit is 200.
``````
##### Sample Input 2:
``````2
999
30001
``````
##### Sample Output 2:
``````1000
40000
``````
Console