Tap here to switch tabs
Problem
Submissions

Problem: Count the Number of Good Subarrays

med
30 min
Try to solve the Count the Number of Good Subarrays problem.

Statement

Given an integer array nums and an integer k, return the total number of good subarrays of nums.

A subarray is defined as good if there are at least kk pairs of indices (i,j)(i, j) such that i<ji < j and nums[i] is equal to nums[j].

A subarray is a contiguous non empty sequence of elements within an array.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i], k ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count the Number of Good Subarrays

med
30 min
Try to solve the Count the Number of Good Subarrays problem.

Statement

Given an integer array nums and an integer k, return the total number of good subarrays of nums.

A subarray is defined as good if there are at least kk pairs of indices (i,j)(i, j) such that i<ji < j and nums[i] is equal to nums[j].

A subarray is a contiguous non empty sequence of elements within an array.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i], k ≤109\leq 10^9