Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Number of Pairs Satisfying Inequality

XPChallenge Points: 30
levelLevel: Hard

You are given two integer arrays, nums1 and nums2, each containing n elements, and an integer diff. Consider all index pairs (i, j) where i < j. A pair is considered valid if the following condition holds:

(nums1[i] - nums1[j]) ≤ (nums2[i] - nums2[j] + diff)

Your task is to determine how many such valid pairs exist and return that total.
If no pair satisfies the condition, return 0.

Example 1:

Input: nums1 = [1,4,2] nums2 = [1,1,1] diff = 0

Output: 2

Explanation:

Valid pairs: (0,1): 1 - 4 <= 1 - 1 → -3 <= 0 ✓ (0,2): 1 - 2 <= 1 - 1 → -1 <= 0 ✓

Example 2:

Input: nums1 = [5,5,5] nums2 = [1,2,3] diff = 1

Output: 3

Explanation:

Every pair satisfies because values in nums1 are equal. Valid pairs: (0,1), (0,2), (1,2)

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result