Detect Duplicate Login Attempts Within K Events of Each Other
Last updated: November 29, 2026
Quick Overview
Given a list of account IDs in the order login attempts arrived and an integer k, return True if the same account appears twice with at most k events between the two positions (index distance at most k).
Meta
November 29, 20260
0
0 solved
Given a list of account IDs in the order login attempts arrived and an integer k, return True if the same account appears twice with at most k events between the two positions (index distance at most k).
Framed around integrity signals for Facebook login, this checks whether you can maintain a bounded sliding window of recent IDs. The interviewer is looking for a window set or last-seen map and correct eviction.
What the Interviewer Expects
- Recognizes this as a fixed-size sliding window over indices
- Maintains either a last-seen index map or a set of the last k IDs
- Evicts the element that falls out of the window at the right moment
- Gives O(n) time and O(min(n, k)) space
- Handles k = 0
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
- Instead of index distance, use timestamps and a window of T seconds.
- Flag IDs whose values are within t of each other inside the window (near-duplicate device fingerprints).
- How would you shard this check across many login servers?
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: ids, a list of hashable account IDs, and k >= 0. Output: True if there exist i < j with ids[i] == ids[j] and j - i <= k. Otherwise False. The list may be long, so we want a single...
High-Level Design
Keep a set holding exactly the IDs at positions j-k .. j-1. For each new position, if the ID is already in the set we found a close duplicate. Otherwise add it, and once the set represents more than...