Leetcode Problem 1747. Leetflex Banned Accounts

1747. Leetflex Banned Accounts

Leetcode Solutions

Identifying Accounts for Banning Based on Concurrent Logins from Different IP Addresses

Algorithm

  1. Perform a cross join on the LogInfo table with itself to create a new table that contains all possible pairs of login sessions.
  2. Apply a filter to keep only the rows where the account_id is the same but the ip_address is different, indicating potential concurrent logins from different locations.
  3. Further filter the rows to keep only those where the login sessions overlap. This is determined by checking if one session's login time is before the other's logout time, and vice versa.
  4. From the filtered results, select the distinct account_ids, as these represent the accounts that violated the login policy and should be banned.
  5. Return the list of account_ids to be banned.

erDiagram
    LogInfo {
        int account_id
        int ip_address
        datetime login
        datetime logout
    }

Using Subquery and Group By to Identify Bannable Accounts

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...