Back to course home
0% completed
Vote For New Content
Solution: Count the Number of Good Subarrays
Problem Statement
Given an array of integers nums, and an integer k, find the count of "good" subarrays within nums.
A subarray is considered "good" if it contains at least k pairs of elements (i, j) where i < j and nums[i] == nums[j].
A subarray is a contiguous sequence of elements in the original array.
Examples
- Example 1:
- Input:
nums = [2, 2, 2, 3, 3], k = 3 - Expected Output:
3 - Justification: There are 3 good subarrays that meet the criteria:
[2, 2, 2, 3],[2, 2, 2, 3, 3], and[2, 2, 2]
- Input:
.....
.....
.....
Like the course? Get enrolled and start learning!