Problem Β· Sliding Window
Transaction Logs β Trigger / Resolve Alerts
Learn this problemProblem statement
Process error-log rows in nondecreasing timestamp order. Each row is "timestamp,merchant_id,status_code,count".
For each (merchant_id, status_code) pair, maintain the sum of count values in the sliding window (timestamp - windowSize, timestamp]. Before adding the current row, remove earlier rows for that pair whose timestamp is at most timestamp - windowSize; then add the current row's count.
Each pair starts below the threshold. Emit "TRIGGER merchant_id status_code" when its rolling sum crosses from below threshold to at least threshold. Emit "RESOLVE merchant_id status_code" when it crosses from at least the threshold to below it. Emit only on transitions and return events in processing order.
Function
processErrorLogs(logs: String[], windowSize: int, threshold: int) β String[]Examples
Example 1
logs = ["1,m1,E1,2","2,m1,E1,3","3,m2,E1,5","12,m1,E1,1"]windowSize = 10threshold = 5return = ["TRIGGER m1 E1","TRIGGER m2 E1","RESOLVE m1 E1"]m1 reaches 5 at time 2. m2 independently reaches 5 at time 3. At time 12, m1's rows at times 1 and 2 have expired, so its sum becomes 1 and resolves.
Example 2
logs = ["5,shop,declined,7","6,shop,timeout,4","7,shop,declined,1","15,shop,declined,2"]windowSize = 10threshold = 8return = ["TRIGGER shop declined","RESOLVE shop declined"]declined reaches 8 at time 7. At time 15, the count 7 from time 5 expires, leaving 1 + 2 = 3, so the pair resolves. timeout is tracked separately.
Constraints
logsare sorted by nondecreasing timestamp.- Every row is
timestamp,merchant_id,status_code,countwith a non-negative integer count. windowSize > 0andthreshold > 0.- A row at time
t0is active attexactly whent0 > t-windowSize. - Different merchant/status pairs are independent.
More Stripe problems
- Group Linked Merchant RecordsPHONE SCREEN Β· Seen Jul 2026
- Invoice / Payment ReconciliationPHONE SCREEN Β· Seen Jul 2026
- Incident MonitorOA Β· Seen Jul 2026
- Merchant Fraud Risk ScoringOA Β· Seen Jul 2026
- WebSocket Load Balancer β Basic Load Balancing (Part 1)OA Β· Seen Jul 2026
- Rule-Driven Transaction Fraud DetectionOA Β· PHONE SCREEN Β· Seen Jul 2026
- Deployment Window SchedulerOA Β· Seen Jul 2026
- Directly Linked UsersOA Β· Seen Jun 2026