Tasks Count in the Weekend — LeetCode 2298 Python Solution
MediumLeetCode PremiumDatabase
- Problem
- #2298
- Reading time
- 2 min
- Source
- leetcode.com
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
| Measure | Complexity |
|---|---|
| Time | O(n log n) (typical) |
| Space | O(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.