Users That Actively Request Confirmation Messages — LeetCode 1939 Python Solution

EasyLeetCode PremiumDatabase
Problem
#1939
Reading time
3 min

Table schema

SQL
Table: Signups +----------------+----------+ | Column Name | Type | +----------------+----------+ | user_id | int | | time_stamp | datetime | +----------------+----------+ user_id is the column with unique values for this table. Each row contains information about the signup time for the user with ID user_id.

Example

SQL
+----------------+----------+
| Column Name    | Type     |
+----------------+----------+
| user_id        | int      |
| time_stamp     | datetime |
+----------------+----------+
user_id is the column with unique values for this table.
Each row contains information about the signup time for the user with ID user_id.

Python solution

Python
import duckdb
import pandas as pd

def solution(signups: pd.DataFrame, confirmations: pd.DataFrame) -> pd.DataFrame:
    con = duckdb.connect()
    con.register("Signups", signups)
    con.register("Confirmations", confirmations)
    return con.execute("""SELECT DISTINCT user_id
FROM
    Confirmations AS c1
    JOIN Confirmations AS c2 USING (user_id)
WHERE
    c1.time_stamp < c2.time_stamp
    AND TIMESTAMPDIFF(SECOND, c1.time_stamp, c2.time_stamp) <= 24 * 60 * 60;""").df()

Complexity

MeasureComplexity
TimeO(n log n) (typical)
SpaceO(n) auxiliary

Related problems

Frequently asked questions

How hard is LeetCode 1939. Users That Actively Request Confirmation Messages?
LeetCode 1939. Users That Actively Request Confirmation Messages is rated Easy on LeetCode.
What topics does LeetCode 1939. Users That Actively Request Confirmation Messages cover?
LeetCode 1939. Users That Actively Request Confirmation Messages is tagged Database on LeetCode.
Is LeetCode 1939. Users That Actively Request Confirmation Messages a premium problem?
Yes. LeetCode 1939. Users That Actively Request Confirmation Messages is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview