Next Greater Even Number
Submissions: 2828   Accuracy:

22.2%

  Difficulty: Easy   Marks: 2

Given a positive integer N. The task is to find the smallest even number E such that E > N and digits in N and E are same.

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 an integer N.

Output:
For each test case in a new line print the required smallest even number. If no such even number exist print -1.

Constraints:
1 <= T <= 105
1 <= N <= 1018

Example:
Input:

2
34722641
111

Output:
34724126
-1

Explanation:
Testcas 1:
Next greater number with same digits as in input is 34724126.

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: Shubham Joshi 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.