Your question is Sliding-Window Hashmap Aggregation. 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.
An AMD ROCm profiling pipeline receives metric labels emitted by consecutive GPU events. Given the labels and a window size, return the number of distinct labels in every contiguous window of exactly k events.
Implement an efficient sliding-window solution using a hash map. When a label enters the window, update its frequency. When a label leaves, decrement its frequency and remove it when the frequency reaches zero.
Implement distinct_metrics_in_windows(events, k).
events: a list of strings representing consecutive ROCm metric labels.k: a positive integer window size.i is the number of distinct labels in events[i:i + k].k is greater than the number of events, return an empty list.def distinct_metrics_in_windows(events, k):