Three Hits in the Last Three Seconds
Updated
Problem statement
A website counts hits and wants to notice bursts. For example, hits at seconds 1, 2 and 3 are 3 hits in the last 3 seconds at second 3.
You get two arrays of the same length, operations and timestamps. Run them from first to last on a monitor that starts with no hits. operations[i] happens at second timestamps[i].
"hit": one hit happens at this second. Several hits can happen in the same second, and each one counts."check": answer whether the last 3 seconds hold at least 3 hits. At secondt, the last 3 seconds are the secondst - 2,t - 1andt. Count every hit so far that happened in those seconds, including hits at secondtthat came earlier in the arrays. A check changes nothing.
Return a list with one boolean for each "check", in the order they run: true when the count is at least 3 and false otherwise. If there is no "check", return an empty list.
Function
runHitMonitor(operations: String[], timestamps: int[]) → boolean[]Examples
Example 1
operations = ["hit","hit","check","hit","check","check"]timestamps = [1,2,2,3,3,6]return = [false,true,false]At time 2 the window is seconds 0 to 2 and holds the hits at times 1 and 2: 2 hits, so false. At time 3 the window is seconds 1 to 3 and holds the hits at 1, 2 and 3: 3 hits, so true. At time 6 the window is seconds 4 to 6 and holds no hits, so false. The answer is [false,true,false].
Example 2
operations = ["hit","hit","hit","check","check","check"]timestamps = [5,5,5,5,7,8]return = [true,true,false]Three hits in the same second all count, so the check at time 5 is true. At time 7 the window is seconds 5 to 7, which still holds the three hits at time 5, so it is true. At time 8 the window is seconds 6 to 8, which holds none, so it is false. The answer is [true,true,false].
Example 3
operations = ["hit","hit","check","hit","hit","hit","check"]timestamps = [10,11,11,12,13,13,13]return = [false,true]At time 11 the window holds the hits at 10 and 11: 2 hits, so false. Later hits keep counting. At time 13 the window is seconds 11 to 13 and holds the hits at 11, 12, 13 and 13: 4 hits, which is at least 3, so true. The answer is [false,true].
Constraints
1 <= operations.length <= 10000timestamps.length == operations.length- Each
operations[i]is"hit"or"check". 0 <= timestamps[i] <= 1000000000timestampsis nondecreasing: an operation never happens earlier than the one before it. Several operations can share the same second.
More Bloomberg LP Phone Screen questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Rolling Hit CounterDatabricks · PHONE SCREEN · ONSITE INTERVIEWDatabricks interview questions
- Per-Client API Rate LimiterDocker · PHONE SCREEN
- Per-Client Sliding-Window Rate LimiterCVS Health · PHONE SCREEN
- Rolling CSAT TrackerDecagon · PHONE SCREEN · ONSITE INTERVIEWDecagon interview questions
- Sliding-Window Rate LimiterUber · PHONE SCREENUber interview questions
- Recent Advertisement Click CountsAmazon · PHONE SCREEN
- Delayed Streaming Duplicate SuppressionGoogle · PHONE SCREENGoogle interview questions
- Completions API Rate LimiterCursor · PHONE SCREENCursor interview questions
- Sliding-Window Rate LimiterStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
- Moving Average of a Data StreamSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions