Grokking Amazon Coding Interview
Ask Author
Back to course home

0% completed

Solution: Count the Number of Good Subarrays
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

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]

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible