Flag Brute Force Login Attempts in a Sliding Window
Last updated: November 29, 2026
Quick Overview
Given a time-ordered stream of login events (timestamp, user, success), return the users who reach at least k failed logins within any window of w seconds, where a successful login resets that user's failure count. Report each user once, in the order they were first flagged.
Okta
November 29, 20260
0
0 solved
Given a time-ordered stream of login events (timestamp, user, success), return the users who reach at least k failed logins within any window of w seconds, where a successful login resets that user's failure count. Report each user once, in the order they were first flagged.
Okta's ThreatInsight and account lockout policies watch System Log authentication events for password spraying and credential stuffing, so a phone screen often opens with a small detector over a login stream. The interviewer checks that you pick per-user state, evict stale timestamps correctly, and pin down boundary semantics before coding.
What the Interviewer Expects
- Asks whether the window boundary is inclusive and whether a success resets the count
- Keeps one deque of failure timestamps per user in a hash map
- Evicts timestamps that have fallen out of the window before checking the threshold
- Reports each user once in first-flagged order
- States O(n) amortized time and memory bounded by failures in the window
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you also flag a single IP spraying many different users?
- Events arrive slightly out of order (up to 5 seconds late). What changes?
- How do you bound memory when millions of users are active?
- How would you shard this across workers in a streaming pipeline?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input is a list of (timestamp, user, success) sorted by timestamp. A user is flagged the first time they have k or more failures whose timestamps lie in (now - w, now]. A successful login clears...
High-Level Design
Keep a map user -> deque of failure timestamps. On a failure, append the timestamp and pop from the left while the oldest is at or before ts - w. If the deque length reaches k, flag the user. On...