Given a list of integers nums and an integer k, return the length of the longest contiguous subarray that contains at most k distinct integers. Examples of valid subarrays are contiguous slices of the original list. If k is 0, the answer should be 0. The function should run efficiently for large lists (linear time expected).
([1, 2, 1, 2, 3], 2)4