Magicsheet logo

Leetflex Banned Accounts

Medium
100%
Updated 6/1/2025

Asked by 1 Company

Topics

Leetflex Banned Accounts

What is this problem about?

The "Leetflex Banned Accounts interview question" is a SQL problem centered around security and concurrency. You are provided with a log of user logins and logouts, including the IP addresses used. A "banned" scenario occurs if a single account is accessed from two different IP addresses at the same time (i.e., the time intervals of the sessions overlap). Your goal is to identify all such user IDs. This "Leetflex Banned Accounts coding problem" is a practical application of interval overlapping logic in a database context.

Why is this asked in interviews?

This question is asked to test a candidate's ability to reason about temporal data and interval overlaps within a "Database interview pattern". It is highly relevant for roles involving system security, fraud detection, and account management. It checks if you can effectively use self-joins to compare different rows within the same table to find conflicting time windows.

Algorithmic pattern used

The problem is solved using a self-join on the login history table. You join the table with itself on the user ID, with the additional condition that the IP addresses must be different. The core logic then checks for an overlap between two intervals [login1, logout1] and [login2, logout2]. Two intervals overlap if login1 <= logout2 AND login2 <= logout1.

Example explanation

Suppose User 10 has two login records:

  1. IP: 1.1.1.1, Login: 10:00, Logout: 10:30
  2. IP: 2.2.2.2, Login: 10:15, Logout: 10:45 Since 10:15 (Login 2) is before 10:30 (Logout 1), the sessions overlap. Because the IP addresses are different, User 10 is flagged. If the second login was at 10:31, there would be no overlap, and the user would not be flagged.

Common mistakes candidates make

  • Incorrect overlap logic: Using complex nested IF statements instead of the simple start1 <= end2 AND start2 <= end1 formula.
  • Ignoring the IP address: Forgetting to check that the IPs must be different (multiple sessions from the same IP are often allowed).
  • Handling edge cases: Not considering sessions that start and end at the exact same time as overlaps.

Interview preparation tip

Interval overlap is a very common theme in both algorithmic and database questions. Memorize the standard overlap condition. Also, practice visualizing these intervals on a timeline to verify your logic quickly during an interview.

Similar Questions