The Inverting Factor
Submissions: 2243   Accuracy:

48.03%

  Difficulty: Easy   Marks: 2

Ishaan being curious as always, was playing with numbers when he started to reversing the numbers. He invented something called the "inverting factor" of two numbers.
Inverting Factor of 2 integers is defined as the absolute difference between the reverse of the 2 integers.
Ishaan has an array A of N integers. He wants to find out the smallest possible Inverting Factor among all pairs of his integers. Help him find that.
Note : Trailing zeros in a number of ignored while reversing, i.e. 1200 becomes 21 when reversed.

Input : 
First line of input contains a single integer T denoting the number of test cases.
The first line of each test case contains an integer N.
The second line contains N space-separated integers denoting the array A.

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

Constraints : 
1 <= T <= 100
2 <= N <= 1000
1 <= A[i] <= 10^5

Example : 
Input : 

3
5
56 20 47 93 45
6
48 23 100 71 56 89
4
26 15 45 150
Output : 
9
14
0

Explanation : 
Case 1 : 
The minimum inverting factor is 9, of the pair (56,47)

Case 2 : 
The minimum inverting factor is 14, of the pair (48,89)

Case 3 : 
The minimum inverting factor is 0, of the pair (15,150)

 

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

Author: goyalanubhav11


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.