CHEF N TIMINGS APOC2_04 SOLUTION

CHEF N TIMINGS SOLUTION

One day chef was working with some random numbers. Then he found something interesting. He observed that no 240, 567, 9999 and 122 and called these numbers nice as the digits in numbers are in increasing order. Also he called 434, 452, 900 are not nice as digits are in decreasing order
 
Now you are given a no and chef wants you to find out largest “nice” integer which is smaller than or equal to the given integer.
Constraints
1< t < 1000
1< N < 10^18
 
Input Format
First line contains no. of test cases t. Then t test cases follow. Each test case contain a integer n.
 
Output
Output a integer for each test case in a new line which is largest nice integer smaller or equal to the given integer.
 
Example Text Case
Input:
 
1
132
 
Output:
 
129
 
SOLUTION AFTER CONTEST(POLICY ISSUE)

Leave a Comment