MediumNo. 1747LeetCode Premium
Leetflex Banned Accounts — LeetCode 1747 Python Solution
- Topics
- Database
- Reading time
- 3 min
- Source
- leetcode.com
Table schema
Table: LogInfo +-------------+----------+ | Column Name | Type | +-------------+----------+ | account_id | int | | ip_address | int | | login | datetime | | logout | datetime | +-------------+----------+ This table may contain duplicate rows. The table contains information about the login and logout dates of Leetflex accounts.Example
+-------------+----------+
| Column Name | Type |
+-------------+----------+
| account_id | int |
| ip_address | int |
| login | datetime |
| logout | datetime |
+-------------+----------+
This table may contain duplicate rows.
The table contains information about the login and logout dates of Leetflex accounts. It also contains the IP address from which the account was logged in and out.
It is guaranteed that the logout time is after the login time.Python solution
import duckdb
import pandas as pd
def solution(log_info: pd.DataFrame) -> pd.DataFrame:
con = duckdb.connect()
con.register("LogInfo", log_info)
return con.execute("""SELECT DISTINCT
a.account_id
FROM
LogInfo AS a
JOIN LogInfo AS b
ON a.account_id = b.account_id
AND a.ip_address != b.ip_address
AND a.login BETWEEN b.login AND b.logout;""").df()Complexity
- Time
- O(n log n)(typical)
- Space · auxiliary
- O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0175 | Combine Two Tables | Easy |
| 0176 | Second Highest Salary | Medium |
| 0177 | Nth Highest Salary | Medium |
| 0178 | Rank Scores | Medium |
| 0180 | Consecutive Numbers | Medium |
| 0181 | Employees Earning More Than Their Managers | Easy |
Frequently asked questions
- How hard is LeetCode 1747. Leetflex Banned Accounts?
LeetCode 1747. Leetflex Banned Accounts is rated Medium on LeetCode.
- What topics does LeetCode 1747. Leetflex Banned Accounts cover?
LeetCode 1747. Leetflex Banned Accounts is tagged Database on LeetCode.
- Is LeetCode 1747. Leetflex Banned Accounts a premium problem?
Yes. LeetCode 1747. Leetflex Banned Accounts is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.