Design a throttling mechanism for repeated FPS game events.
In a first-person shooter, players trigger actions like shooting, reloading or throwing grenades by pressing keys, and pressing the same key repeatedly in a short period can cause excessive event triggers. Design a throttling mechanism so the same event type can only be triggered once within a given delay period. If the same event occurs again before the delay expires, it is ignored. Each event type is handled independently.
Example: delay = 5, events: [("shoot", 1), ("shoot", 2), ("reload", 3), ("shoot", 6)] -> output: [true, false, true, true].
Candidate's approach: keep a map from event type to last-triggered timestamp; allow and update when now - last >= delay, otherwise ignore. A ConcurrentHashMap handles multithreading.
Expect follow-ups like
- Can you find a more optimal approach?
Format · Oracle Senior Software Engineer phone screen (USA).
Community answers
Related courses


