Problem

Submissions

Solution

New

Discuss

3

Difficulty: EASY

Avg. time to solve

10 min

Success Rate

90%

Problem Statement

Suggest Edit

```
You can use swap operation over any two indices i,e you can choose two indices 'i' and 'j' and swap the digits present at S[i] and S[j]. But this operation can be used only once.
Your final even number should be the largest out of all other possible even numbers.
```

```
If it isn’t possible to make an even number print -1
```

```
The first line of the input contains ‘T’ denoting the number of test cases.
The first and the only line of each test case contains a string ‘S’ the odd number.
```

```
If it is possible to make even number print largest out of all. Else print -1
Print the result of each test case in a new line.
```

```
1 <= T <= 5
0 <= |S| <= 10^5
Time Limit : 1 sec
```

```
3
652345
79345
31179
```

```
655342
79354
-1
```

```
In test case 1:
552346, 655342, 652354 are the all possible even number which can be made by only using 1 swap operation.
Out of which 655342 is the largest, hence the answer.
In test case 2:
The only possible even number is 79354.
In test case 3:
There is no possible way to swap two digits to make the number even.
```

```
2
635875915
64966689669
```

```
635575918
94966689666
```

Console