QuickBooks receives transactions in chronological order, represented by integer category IDs. Given the category sequence and a limit k, find the length of the longest contiguous range containing at most k distinct categories.
A range must contain at least one transaction. Return 0 only when the input sequence is empty or k is zero.
Implement longest_category_window(categories, k).
categories, an array of integers, and k, a non-negative integer.k distinct values.def longest_category_window(categories, k):