Exchange Connection Alerts
Updated
Problem statement
Each event is [time,app,exchange], meaning that an application connects to an exchange at that integer time. Process events in their given order. Before inserting an event at time t, expire all earlier events with time at most t-window. Active events therefore lie in (t-window,t].
For each exchange, count distinct applications with at least one active event. Repeated events for the same pair count as one application until all its events expire. For each inserted event, return its exchange id only when the insertion changes that exchange count from at most threshold to greater than threshold. Otherwise return -1.
Return one result per event. Expiration alone emits no alarm. An exchange can alarm again after enough connections expire and a later insertion crosses the threshold again. Equal-time events are processed in input order.
Function
exchangeAlerts(events: int[][], window: int, threshold: int) → int[]Examples
Example 1
events = [[0,1,7],[1,2,7],[2,1,7],[3,3,7],[7,4,7]]window = 5threshold = 2return = [-1,-1,-1,7,-1]At time 3, exchange 7 has applications 1, 2, and 3, so adding application 3 crosses the threshold of 2. At time 7, events at times 0, 1, and 2 have expired. Application 3 remains, and adding application 4 raises the count only to 2.
Example 2
events = [[0,1,5],[0,2,5],[2,3,5],[2,4,5]]window = 2threshold = 1return = [-1,5,-1,5]The second event crosses from one distinct application to two. At time 2, both time-0 events expire because the left window boundary is excluded. Application 3 starts a new count of one; application 4 then causes another crossing.
Constraints
0 <= events.length <= 100000.- Every event contains exactly three integers.
0 <= events[i][j] <= 10^9.1 <= window <= 10^9.0 <= threshold <= 100000.- Event timestamps are nondecreasing.
More Citadel Onsite Interview questions
- Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Removal PoolONSITE INTERVIEW · Seen Sep 2026
- Centered K-by-K Submatrix SumsONSITE INTERVIEW · Seen Aug 2026
- Search Suggestions with a Prefix TreeONSITE INTERVIEW · Seen Aug 2026
- Traverse Interior Matrix Cells in Row-Major OrderONSITE INTERVIEW · Seen Aug 2026
- Time-Based Key-Value StorePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2026
- 2048 Simulation and Board CodecONSITE INTERVIEW · Seen Jan 2026
- Cancellable Priority Task QueueONSITE INTERVIEW · Seen Jan 2026
- Dynamic Weighted SamplingONSITE INTERVIEW · Seen Jan 2026
Similar questions at other companies
- Sliding-Window Rate LimiterAmazon · ONSITE INTERVIEW
- High-Traffic IPs in a Sliding WindowGoogle · ONSITE INTERVIEWGoogle interview questions
- Rate Limiter with Global and Per-User LimitsOpenAI · ONSITE INTERVIEWOpenAI interview questions
- Per-Element Hit CounterUber · ONSITE INTERVIEWUber interview questions
- Rate Limiter Sliding Window With Per-Entity LimitsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Metric Counter with a Fake ClockSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
- Per-Client Sliding-Window Rate LimiterNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
- Sliding-Window Rate LimiterStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
- Transaction Authorizer with Velocity RulesGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Per-Client API Rate LimiterDocker · PHONE SCREEN