Class Solution
-
- All Implemented Interfaces:
public final class Solution1855 - Maximum Distance Between a Pair of Values\.
Medium
You are given two non-increasing 0-indexed integer arrays
nums1andnums2.A pair of indices
(i, j), where0 <= i < nums1.lengthand0 <= j < nums2.length, is valid if bothi <= jandnums1[i] <= nums2[j]. The distance of the pair isj - i.Return the maximum distance of any valid pair
(i, j). If there are no valid pairs, return0.An array
arris non-increasing ifarr[i-1] >= arr[i]for every1 <= i < arr.length.Example 1:
Input: nums1 = 55,30,5,4,2, nums2 = 100,20,10,10,5
Output: 2
Explanation: The valid pairs are (0,0), (2,2), (2,3), (2,4), (3,3), (3,4), and (4,4). The maximum distance is 2 with pair (2,4).
Example 2:
Input: nums1 = 2,2,2, nums2 = 10,10,1
Output: 1
Explanation: The valid pairs are (0,0), (0,1), and (1,1). The maximum distance is 1 with pair (0,1).
Example 3:
Input: nums1 = 30,29,19,5, nums2 = 25,25,25,25,25
Output: 2
Explanation: The valid pairs are (2,2), (2,3), (2,4), (3,3), and (3,4). The maximum distance is 2 with pair (2,4).
Constraints:
<code>1 <= nums1.length, nums2.length <= 10<sup>5</sup></code>
<code>1 <= nums1i, nums2j<= 10<sup>5</sup></code>
Both
nums1andnums2are non-increasing.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegermaxDistance(IntArray nums1, IntArray nums2)-
-
Method Detail
-
maxDistance
final Integer maxDistance(IntArray nums1, IntArray nums2)
-
-
-
-