Tap here to switch tabs
Problem
Submissions

Problem: Maximum Distance Between a Pair of Values

med
30 min
Try to solve the Maximum Distance Between a Pair of Values problem.

Statement

You are given two 00 indexed integer arrays, nums1 and nums2, both sorted in nonincreasing order.

A pair of indices (i, j) is considered valid if 0≤0 \leq i << nums1.length, 0≤0 \leq j << nums2.length, i ≤\leq j, and nums1[i] ≤\leq nums2[j]. The distance of this pair is j −- i.

Return the maximum distance of any valid pair (i, j). If no valid pairs exist, return 00.

Constraints:

  • 1≤1 \leq nums1.length, nums2.length ≤105\leq 10^5

  • 1≤1 \leq nums1[i], nums2[j] ≤105\leq 10^5

  • Both nums1 and nums2 are sorted in nonincreasing order.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Distance Between a Pair of Values

med
30 min
Try to solve the Maximum Distance Between a Pair of Values problem.

Statement

You are given two 00 indexed integer arrays, nums1 and nums2, both sorted in nonincreasing order.

A pair of indices (i, j) is considered valid if 0≤0 \leq i << nums1.length, 0≤0 \leq j << nums2.length, i ≤\leq j, and nums1[i] ≤\leq nums2[j]. The distance of this pair is j −- i.

Return the maximum distance of any valid pair (i, j). If no valid pairs exist, return 00.

Constraints:

  • 1≤1 \leq nums1.length, nums2.length ≤105\leq 10^5

  • 1≤1 \leq nums1[i], nums2[j] ≤105\leq 10^5

  • Both nums1 and nums2 are sorted in nonincreasing order.