Class Solution
java.lang.Object
g2401_2500.s2426_number_of_pairs_satisfying_inequality.Solution
2426 - Number of Pairs Satisfying Inequality.<p>Hard</p>
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, each of size <code>n</code>, and an integer <code>diff</code>. Find the number of <strong>pairs</strong> <code>(i, j)</code> such that:</p>
<ul>
<li><code>0 <= i < j <= n - 1</code> <strong>and</strong></li>
<li><code>nums1[i] - nums1[j] <= nums2[i] - nums2[j] + diff</code>.</li>
</ul>
<p>Return <em>the <strong>number of pairs</strong> that satisfy the conditions.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums1 = [3,2,5], nums2 = [2,2,1], diff = 1</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong></p>
<p>There are 3 pairs that satisfy the conditions:</p>
<ol>
<li>
<p>i = 0, j = 1: 3 - 2 <= 2 - 2 + 1. Since i < j and 1 <= 1, this pair satisfies the conditions.</p>
</li>
<li>
<p>i = 0, j = 2: 3 - 5 <= 2 - 1 + 1. Since i < j and -2 <= 2, this pair satisfies the conditions.</p>
</li>
<li>
<p>i = 1, j = 2: 2 - 5 <= 2 - 1 + 1. Since i < j and -3 <= 2, this pair satisfies the conditions.</p>
</li>
</ol>
<p>Therefore, we return 3.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums1 = [3,-1], nums2 = [-2,2], diff = -1</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong></p>
<p>Since there does not exist any pair that satisfies the conditions, we return 0.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == nums1.length == nums2.length</code></li>
<li><code>2 <= n <= 10<sup>5</sup></code></li>
<li><code>-10<sup>4</sup> <= nums1[i], nums2[i] <= 10<sup>4</sup></code></li>
<li><code>-10<sup>4</sup> <= diff <= 10<sup>4</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
numberOfPairs
public long numberOfPairs(int[] nums1, int[] nums2, int diff)
-