LeetCode 624, Medium. Topics: Array, Greedy. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 11 parametrized pytest cases, and a playground notebook:
Problem
You are given m arrays, where each array is sorted in ascending order.
You can pick up two integers from two different arrays (each array picks one) and calculate the distance. We define the distance between two integers a and b to be their absolute difference |a - b|.
Return the maximum distance.
Examples
Constraints
- m == arrays.length
- 2 <= m <= 10^5
- 1 <= arrays[i].length <= 500
- -10^4 <= arrays[i][j] <= 10^4
- arrays[i] is sorted in ascending order.
- There will be at most 10^5 integers in all the arrays.
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026