Maximum Distance in Arrays

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.

30:00

Maximum Distance in Arrays
medium
Free written solution
Topics
Companies

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.lengthm == \text{arrays.length}

  • 2≤m≤1052 \leq m \leq 10^5

  • 1≤arrays[i].length≤5001 \leq \text{arrays}[i].\text{length} \leq 500

  • −104≤arrays[i][j]≤104-10^4 \leq \text{arrays}[i][j] \leq 10^4

  • arrays[i]\text{arrays}[i] is sorted in ascending order.

  • There will be at most 10510^5 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.

lo (smallest first)

-

hi (largest last)

-

best

0

each array drawn from its first to its last value

013145213
Variables
No variables to display
DepthFunction Call
Stack empty
0/5