Leaderboard
Showing:
Previous number in one swap
Medium Accuracy: 11.46% Submissions: 2096 Points: 4

Given a non-negative number N in the form of string. The task is to apply at most one swap operation on the number N so that the resultant is just previous possible number.

Note:  Leading zeros are not allowed.

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

Output:
For each test case, print the just previous possible number you can have in one swap. if it is not possible to make previous number then print "-1".

Constraints:
1<=T<=200
2<=|Number length |<=105

Example:
Input:
2

354
999

Output:
345
-1

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.

Previous number in one swap

Output Window