Find the largest number
Medium Accuracy: 16.77% Submissions: 1739 Points: 4

Given an integer N the task is to find the largest number which is smaller or equal to it and has its digits in non decreasing order.

Examples:

Examples:

Input  : n = 200
Output : 199
If the given number is 200, the largest 
number which is smaller or equal to it 
having digits in non decreasing order is
199.

Input  : n = 139
Output : 139


Input:
The first  line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contain an integer N.

Output:
For each test case in a new line print the required output.

Constraints:
1<=T<=200
1<=N<=100000000

Example:
Input:

2
200
139
Output:
199
139

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.