You are given m arrays, each sorted in ascending order. Pick two integers from two different arrays and compute the distance |a - b|. Return the maximum distance.
You are given m arrays, each sorted in ascending order. Pick two integers from two different arrays and compute the distance |a - b|. Return the maximum distance.
Example 1:
Input: {"arrays":[[1,2,3],[4,5],[1,2,3]]}
Output: 4
Constraints:
m==arrays.length
2≤m≤105
1≤arrays[i].length≤500
−104≤arrays[i][j]≤104
arrays[i] is sorted in ascending order.
There will be at most 105 integers in all the arrays.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"arrays":[[1,2,3],[4,5],[1,2,3]]}
3 sorted arrays. Only each array's first and last value can matter, because the answer is always a big end minus a small end.