Class Solution
- java.lang.Object
-
- g2501_2600.s2537_count_the_number_of_good_subarrays.Solution
-
public class Solution extends Object
2537 - Count the Number of Good Subarrays.Medium
Given an integer array
nums
and an integerk
, return the number of good subarrays ofnums
.A subarray
arr
is good if it there are at leastk
pairs of indices(i, j)
such thati < j
andarr[i] == arr[j]
.A subarray is a contiguous non-empty sequence of elements within an array.
Example 1:
Input: nums = [1,1,1,1,1], k = 10
Output: 1
Explanation: The only good subarray is the array nums itself.
Example 2:
Input: nums = [3,1,4,3,2,2,4], k = 2
Output: 4
Explanation: There are 4 different good subarrays:
-
[3,1,4,3,2,2] that has 2 pairs.
-
[3,1,4,3,2,2,4] that has 3 pairs.
-
[1,4,3,2,2,4] that has 2 pairs.
-
[4,3,2,2,4] that has 2 pairs.
Constraints:
1 <= nums.length <= 105
1 <= nums[i], k <= 109
-
-
-
Constructor Summary
Constructors Constructor Description Solution()
-