Algorithm · Squarepoint · Medium
Given an array nums of positive integers and an integer k, a contiguous, non-empty subarray is considered good when the number of distinct values inside it is at least k. Implement: Return the smallest possible length of a good subarray. If no contiguous subarray reaches k distinct values, return -1. When counting distinct values, repeated numbers add only once to the total. Example 1: Explanation: The subarray [1, 2, 3, 4] contains four distinct values, and no shorter…
Checking your access…