Tasks Count in the Weekend — LeetCode 2298 Python Solution

MediumLeetCode PremiumDatabase
Problem
#2298
Reading time
2 min

Table schema

SQL
Table: Tasks +-------------+------+ | Column Name | Type | +-------------+------+ | task_id | int | | assignee_id | int | | submit_date | date | +-------------+------+ task_id is the primary key (column with unique values) for this table. Each row in this table contains the ID of a task, the id of the assignee, and the submission date.

Example

SQL
+-------------+------+
| Column Name | Type |
+-------------+------+
| task_id     | int  |
| assignee_id | int  |
| submit_date | date |
+-------------+------+
task_id is the primary key (column with unique values) for this table.
Each row in this table contains the ID of a task, the id of the assignee, and the submission date.

Python solution

Python
import duckdb
import pandas as pd

def solution(tasks: pd.DataFrame) -> pd.DataFrame:
    con = duckdb.connect()
    con.register("Tasks", tasks)
    return con.execute("""SELECT
    SUM(WEEKDAY(submit_date) IN (5, 6)) AS weekend_cnt,
    SUM(WEEKDAY(submit_date) NOT IN (5, 6)) AS working_cnt
FROM Tasks;""").df()

Complexity

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

Related problems

Frequently asked questions

How hard is LeetCode 2298. Tasks Count in the Weekend?
LeetCode 2298. Tasks Count in the Weekend is rated Medium on LeetCode.
What topics does LeetCode 2298. Tasks Count in the Weekend cover?
LeetCode 2298. Tasks Count in the Weekend is tagged Database on LeetCode.
Is LeetCode 2298. Tasks Count in the Weekend a premium problem?
Yes. LeetCode 2298. Tasks Count in the Weekend 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