#K38252. Maximum Absolute Difference
Maximum Absolute Difference
Maximum Absolute Difference
You are given two integer arrays A
and B
each of length N. For each test case, your task is to find the maximum absolute difference between any element from A
and any element from B
. More formally, the answer for a test case is given by:
$$ \max\Big(|\max A - \min B|,\, |\min A - \max B|\Big) $$
The input starts with an integer T
specifying the number of test cases. For every test case:
- The first line contains an integer
N
, which indicates the length of the arrays. - The second line contains
N
space-separated integers representing the arrayA
. - The third line contains
N
space-separated integers representing the arrayB
.
For each test case, print the maximum absolute difference on a new line.
inputFormat
The first line of the input contains a single integer T
– the number of test cases. The description of the test cases follows.
For each test case:
- The first line contains an integer
N
representing the number of elements in the arrays. - The second line contains
N
space-separated integers, the elements of arrayA
. - The third line contains
N
space-separated integers, the elements of arrayB
.
outputFormat
For each test case, output a single line containing the maximum absolute difference calculated as:
$$ \max\Big(|\max A - \min B|,\, |\min A - \max B|\Big) $$
## sample1
3
1 2 3
4 5 6
5