|
| 1 | +<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the number of <strong>good</strong> subarrays of</em> <code>nums</code>.</p> |
| 2 | + |
| 3 | +<p>A subarray <code>arr</code> is <strong>good</strong> if there are <strong>at least </strong><code>k</code> pairs of indices <code>(i, j)</code> such that <code>i < j</code> and <code>arr[i] == arr[j]</code>.</p> |
| 4 | + |
| 5 | +<p>A <strong>subarray</strong> is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p> |
| 6 | + |
| 7 | +<p> </p> |
| 8 | +<p><strong class="example">Example 1:</strong></p> |
| 9 | + |
| 10 | +<pre> |
| 11 | +<strong>Input:</strong> nums = [1,1,1,1,1], k = 10 |
| 12 | +<strong>Output:</strong> 1 |
| 13 | +<strong>Explanation:</strong> The only good subarray is the array nums itself. |
| 14 | +</pre> |
| 15 | + |
| 16 | +<p><strong class="example">Example 2:</strong></p> |
| 17 | + |
| 18 | +<pre> |
| 19 | +<strong>Input:</strong> nums = [3,1,4,3,2,2,4], k = 2 |
| 20 | +<strong>Output:</strong> 4 |
| 21 | +<strong>Explanation:</strong> There are 4 different good subarrays: |
| 22 | +- [3,1,4,3,2,2] that has 2 pairs. |
| 23 | +- [3,1,4,3,2,2,4] that has 3 pairs. |
| 24 | +- [1,4,3,2,2,4] that has 2 pairs. |
| 25 | +- [4,3,2,2,4] that has 2 pairs. |
| 26 | +</pre> |
| 27 | + |
| 28 | +<p> </p> |
| 29 | +<p><strong>Constraints:</strong></p> |
| 30 | + |
| 31 | +<ul> |
| 32 | + <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> |
| 33 | + <li><code>1 <= nums[i], k <= 10<sup>9</sup></code></li> |
| 34 | +</ul> |
0 commit comments