Subarrays with K Distinct

A subarray is a contiguous segment of an array. Given an integer array nums and an integer k, return the number of subarrays that contain exactly $k$ distinct integers.

Subarrays differing in start or end index are considered distinct, even when their elements are identical.

Examples
Input: [[1,2,1,2,3],2]
Output: 7

Subarrays with K Distinct

A **subarray** is a contiguous segment of an array. Given an integer array `nums` and an integer `k`, return the number of subarrays that contain **exactly** $k$ distinct integers.