Skip to content

Practice Count the Number of Good Subarrays

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2537
LeetCode Problem

Count the Number of Good Subarrays

Problem Statement

Given an integer array nums and an integer k, return the number of good subarrays of nums. A subarray arr is good if there are at least k pairs of indices (i, j) such that i < j and arr[i] == arr[j]. A subarray is a contiguous non-empty sequence of elements within an array.

Source: Count the Number of Good Subarrays on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,1,1,1,1], k = 10
Output
1

# Example 2

Input
nums = [3,1,4,3,2,2,4], k = 2
Output
4

Constraints

1 <= nums.length <= 10^5
1 <= nums[i], k <= 10^9

Related LeetCode Problems

Practice more problems similar to Count the Number of Good Subarrays.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.