You are given a table LogInfo that contains information about login and logout activities for Leetflex accounts. Each row represents a login session with the account ID, IP address used, and the login/logout timestamps.
Problem: Find all account IDs that should be banned from Leetflex. An account should be banned if it was logged in at some moment from two different IP addresses simultaneously (i.e., there was an overlap in login sessions from different IPs).
Key insight: You need to detect overlapping time periods for the same account but different IP addresses.
Table Schema
| Column Name | Type | Description |
|---|---|---|
account_id
PK
|
int | Account identifier |
ip_address
PK
|
int | IP address used for login |
login
PK
|
datetime | Login timestamp |
logout
|
datetime | Logout timestamp |
Input & Output
| account_id | ip_address | login | logout |
|---|---|---|---|
| 1 | 1 | 2021-02-01 09:00:00 | 2021-02-01 11:00:00 |
| 1 | 2 | 2021-02-01 10:00:00 | 2021-02-01 12:00:00 |
| 2 | 6 | 2021-02-01 13:00:00 | 2021-02-01 15:00:00 |
| 2 | 7 | 2021-02-01 16:00:00 | 2021-02-01 18:00:00 |
| account_id |
|---|
| 1 |
Account 1 should be banned because it was logged in simultaneously from two different IP addresses (1 and 2). The first session (IP 1) was from 09:00 to 11:00, and the second session (IP 2) was from 10:00 to 12:00. These sessions overlap from 10:00 to 11:00.
Account 2 has sessions from different IPs but they don't overlap in time, so it's not banned.
| account_id | ip_address | login | logout |
|---|---|---|---|
| 1 | 1 | 2021-02-01 09:00:00 | 2021-02-01 11:00:00 |
| 1 | 2 | 2021-02-01 12:00:00 | 2021-02-01 14:00:00 |
| 2 | 1 | 2021-02-01 15:00:00 | 2021-02-01 17:00:00 |
| account_id |
|---|
No accounts should be banned. Account 1 used two different IP addresses but the sessions were sequential (11:00 logout, 12:00 login) with no overlap. Account 2 only used one IP address.
| account_id | ip_address | login | logout |
|---|---|---|---|
| 1 | 1 | 2021-02-01 09:00:00 | 2021-02-01 12:00:00 |
| 1 | 1 | 2021-02-01 10:00:00 | 2021-02-01 11:00:00 |
| 2 | 1 | 2021-02-01 13:00:00 | 2021-02-01 15:00:00 |
| account_id |
|---|
No accounts should be banned. Account 1 has overlapping sessions but they use the same IP address (1), which doesn't violate the rule. The rule only applies to simultaneous logins from different IP addresses.
Constraints
-
1 ≤ account_id ≤ 10000 -
1 ≤ ip_address ≤ 10000 -
login < logoutfor all rows - The table may contain duplicate rows