Patients With a Condition — LeetCode 1527 Python Solution
EasyDatabase
- Problem
- #1527
- Reading time
- 2 min
- Source
- leetcode.com
Table schema
SQL
Table: Patients +--------------+---------+ | Column Name | Type | +--------------+---------+ | patient_id | int | | patient_name | varchar | | conditions | varchar | +--------------+---------+ patient_id is the primary key (column with unique values) for this table. 'conditions' contains 0 or more code separated by spaces.Example
SQL
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| patient_id | int |
| patient_name | varchar |
| conditions | varchar |
+--------------+---------+
patient_id is the primary key (column with unique values) for this table.
'conditions' contains 0 or more code separated by spaces.
This table contains information of the patients in the hospital.Python solution
Python
import duckdb
import pandas as pd
def solution(patients: pd.DataFrame) -> pd.DataFrame:
con = duckdb.connect()
con.register("Patients", patients)
return con.execute("""SELECT
patient_id,
patient_name,
conditions
FROM patients
WHERE conditions LIKE 'DIAB1%' OR conditions LIKE '% DIAB1%';""").df()Complexity
| Measure | Complexity |
|---|---|
| Time | O(n log n) (typical) |
| Space | O(n) auxiliary |
Related problems
Frequently asked questions
- How hard is LeetCode 1527. Patients With a Condition?
- LeetCode 1527. Patients With a Condition is rated Easy on LeetCode.
- What topics does LeetCode 1527. Patients With a Condition cover?
- LeetCode 1527. Patients With a Condition is tagged Database on LeetCode.