LC: Maximum Distance in Arrays - spiralgo/algorithms GitHub Wiki
The Essence:
In problem solving, the problem conditions are important for developing an efficient tactic for dealing with problems:
Since each individual array is sorted in ascending order, the maximum distance will be between the first element of some array and the last element of some other array.
Details:
For this, the program should keep the minimum and maximum values in the previously traversed arrays. The last and the first elements of the array should be compared respectively with the maximum and minimum values and update the maximum distance if possible. If the first or the last element is respectively smaller than the previous minimum or greater than the previous maximum, these values are updated as well and the loop continues to other lists.
The code implementation can be found here: https://github.com/spiralgo/algorithms/blob/master/src/main/java/algorithms/curated170/medium/MaximumDistanceInArrays.java