How do you approach Hackerrank-style coding problems?
Implement the described solution for a representative array problem. Given an integer array nums and integer k, return the length of the longest contiguous subarray containing at most k distinct values.
Function signature: longest_subarray_at_most_k_distinct(nums, k)
Return an integer. The input array is non-empty, and values may repeat.
def longest_subarray_at_most_k_distinct(nums, k):