(This question is a variation of the LeetCode question 992. Subarrays with K Different Integers. If you haven't completed that question yet, it is recommended to solve it first.)
Given an integer array arr and an integer k, a subarray is called good if it contains at least k distinct integers. Return the length of the shortest good subarray. If no good subarray exists, return -1.
Constraints:
- 1 ≤
arr.length≤ - 1 ≤
arr[i]≤ - 1 ≤
k≤arr.length
Ask AI Assistant

Ask AI Assistant
Ask me anything about this coding question!
Test Cases
Input
Output
Expected