Your question is Sliding Window or Multi-Pointer Optimization. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Meta IT receives a chronological stream of support event categories from its internal service tooling. Given the category for each event, find the length of the longest contiguous window containing at most k distinct categories.
Use a sliding window or multi-pointer approach that runs in O(n) time.
Implement longest_support_window(events, k).
events, a list of integers where each integer identifies an event category, and k, a non-negative integer.k distinct values.k is 0, return 0.def longest_support_window(events, k):