Longest k-distinct subarray
Your task
Given an integer array a and an integer k, return the length of the longest contiguous subarray that contains at most k distinct values. If k <= 0 or the array is empty, return 0.
Examples
longest_at_most_k_distinct(a: list[int], k: int) -> intExample 1
Input
longest_at_most_k_distinct([1, 2, 1, 2, 3], 2)Output
4