EasyNo. 1435LeetCode Premium
Create a Session Bar Chart — LeetCode 1435 Python Solution
- Topics
- Database
- Reading time
- 3 min
- Source
- leetcode.com
Table schema
Table: Sessions +---------------------+---------+ | Column Name | Type | +---------------------+---------+ | session_id | int | | duration | int | +---------------------+---------+ session_id is the column of unique values for this table. duration is the time in seconds that a user has visited the application.Example
+---------------------+---------+
| Column Name | Type |
+---------------------+---------+
| session_id | int |
| duration | int |
+---------------------+---------+
session_id is the column of unique values for this table.
duration is the time in seconds that a user has visited the application.Python solution
import duckdb
import pandas as pd
def solution(sessions: pd.DataFrame) -> pd.DataFrame:
con = duckdb.connect()
con.register("Sessions", sessions)
return con.execute("""SELECT '[0-5>' AS bin, COUNT(1) AS total FROM Sessions WHERE duration < 300
UNION
SELECT '[5-10>' AS bin, COUNT(1) AS total FROM Sessions WHERE 300 <= duration AND duration < 600
UNION
SELECT '[10-15>' AS bin, COUNT(1) AS total FROM Sessions WHERE 600 <= duration AND duration < 900
UNION
SELECT '15 or more' AS bin, COUNT(1) AS total FROM Sessions WHERE 900 <= duration;""").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 1435. Create a Session Bar Chart?
LeetCode 1435. Create a Session Bar Chart is rated Easy on LeetCode.
- What topics does LeetCode 1435. Create a Session Bar Chart cover?
LeetCode 1435. Create a Session Bar Chart is tagged Database on LeetCode.
- Is LeetCode 1435. Create a Session Bar Chart a premium problem?
Yes. LeetCode 1435. Create a Session Bar Chart is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.