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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Easy

0

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
sliding window
hash set
last-seen index
integrity
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported