Describe how you would solve a medium-level coding challenge end to end, from clarifying requirements to implementing and testing your solution.
For the hands-on portion, implement longest_subarray_at_most_k_distinct(nums, k), returning the length of the longest contiguous subarray containing at most k distinct integers. Inputs are an integer array and a nonnegative integer k; return an integer.
def longest_subarray_at_most_k_distinct(nums, k):