Your question is Implement a Basic Algorithmic Challenge. 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.
TD Mobile alerts group consecutive transactions for analysis. Given a list of merchant identifiers in transaction order and an integer k, find the length of the longest contiguous transaction window containing at most k distinct merchants.
Use a sliding-window approach that runs efficiently for large transaction streams.
Implement longest_alert_window(merchants, k).
merchants, a list of strings representing merchant identifiers, and k, a non-negative integer.k distinct merchant identifiers.0 when k is 0 or the input list is empty.def longest_alert_window(merchants, k):