90. Suspended Accounts

A company needs to detect fraudulent behavior by banning accounts that were simultaneously active from multiple IP addresses, indicating potential account sharing or hacking.

You are given LogInfo Table:

╔═════════════╦══════════╗
ā•‘ Column Name ā•‘   Type   ā•‘
╠═════════════╬══════════╣
ā•‘ account_id  ā•‘   int    ā•‘
║─────────────┼──────────║
ā•‘ ip_address  ā•‘   int    ā•‘
║─────────────┼──────────║
ā•‘   login     ā•‘ datetime ā•‘
║─────────────┼──────────║
ā•‘   logout    ā•‘ datetime ā•‘
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•©ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•
  • account_id: ID of the user/account logging in
  • ip_address: IP address from which the account was logged in
  • login: The timestamp when the user logged in
  • logout: The timestamp when the user logged out
  • The table may contain duplicate rows (same account_id, ip_address, login, and logout).
  • It's confirmed that for every row, logout always happens after login.

Write a query to find the account_id of accounts that should be banned. An account should be banned if it has logged in at any moment from two different IP addresses. Return the result in any order.

Example 1:

Example:

Input:

╔════════════╦════════════╦═════════════════════╦═════════════════════╗
ā•‘ account_id ā•‘ ip_address ā•‘       login         ā•‘       logout        ā•‘
╠════════════╬════════════╬═════════════════════╬═════════════════════╣
ā•‘     1      ā•‘     1      ā•‘ 2021-02-01 09:00:00 ā•‘ 2021-02-01 09:30:00 ā•‘
║────────────┼────────────┼─────────────────────┼─────────────────────║
ā•‘     1      ā•‘     2      ā•‘ 2021-02-01 08:00:00 ā•‘ 2021-02-01 11:30:00 ā•‘
║────────────┼────────────┼─────────────────────┼─────────────────────║
ā•‘     2      ā•‘     6      ā•‘ 2021-02-01 20:30:00 ā•‘ 2021-02-01 22:00:00 ā•‘
║────────────┼────────────┼─────────────────────┼─────────────────────║
ā•‘     2      ā•‘     7      ā•‘ 2021-02-02 20:30:00 ā•‘ 2021-02-02 22:00:00 ā•‘
║────────────┼────────────┼─────────────────────┼─────────────────────║
ā•‘     3      ā•‘     9      ā•‘ 2021-02-01 16:00:00 ā•‘ 2021-02-01 16:59:59 ā•‘
║────────────┼────────────┼─────────────────────┼─────────────────────║
ā•‘     3      ā•‘    13      ā•‘ 2021-02-01 17:00:00 ā•‘ 2021-02-01 17:59:59 ā•‘
║────────────┼────────────┼─────────────────────┼─────────────────────║
ā•‘     4      ā•‘    10      ā•‘ 2021-02-01 16:00:00 ā•‘ 2021-02-01 17:00:00 ā•‘
║────────────┼────────────┼─────────────────────┼─────────────────────║
ā•‘     4      ā•‘    11      ā•‘ 2021-02-01 17:00:00 ā•‘ 2021-02-01 17:59:59 ā•‘
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•©ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•©ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•©ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•

Expected Output:

╔════════════╗
ā•‘ account_id ā•‘
╠════════════╣
ā•‘     1      ā•‘
║────────────║
ā•‘     4      ā•‘
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•

Explanation:

Account 1:

  • Logged in from IP 1 (9:00–9:30) and IP 2 (8:00–11:30) overlapping = Ban.

Account 2:

  • Different IPs, but sessions are on different days = Not banned.

Account 3:

  • Different IPs, but no overlapping sessions = Not banned.

Account 4:

  • Logged in from IP 10 (16:00–17:00) and IP 11 (17:00–17:59) with exact match at 17:00 Overlap = Ban.

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Hints

0
Ā 
Test Case

Input:

LogInfo