2537. Count the Number of Good Subarrays

Medium

602

17

Given an integer array `nums`

and an integer `k`

, return *the number of good subarrays of*

`nums`

.A subarray `arr`

is **good** if it 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.

**Example 1:**

Input:nums = [1,1,1,1,1], k = 10Output:1Explanation:The only good subarray is the array nums itself.

**Example 2:**

Input:nums = [3,1,4,3,2,2,4], k = 2Output:4Explanation: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 <= 10`

^{5}`1 <= nums[i], k <= 10`

^{9}

Accepted

12.8K

Submissions

26.5K

Acceptance Rate

48.2%

Seen this question in a real interview before?

1/4

Yes

No

Discussion (0)

Related Topics

Copyright ©️ 2023 LeetCode All rights reserved