Concatenate the Name and the Profession — LeetCode 2504 Python Solution
EasyLeetCode PremiumDatabase
- Problem
- #2504
- Reading time
- 2 min
- Source
- leetcode.com
Table schema
SQL
Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | person_id | int | | name | varchar | | profession | ENUM | +-------------+---------+ person_id is the primary key (column with a unique value) for this table. Each row in this table contains a person's ID, name, and profession.Example
SQL
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| person_id | int |
| name | varchar |
| profession | ENUM |
+-------------+---------+
person_id is the primary key (column with a unique value) for this table.
Each row in this table contains a person's ID, name, and profession.
The profession column in an enum of the type ('Doctor', 'Singer', 'Actor', 'Player', 'Engineer', or 'Lawyer')Python solution
Python
import duckdb
import pandas as pd
def solution(person: pd.DataFrame) -> pd.DataFrame:
con = duckdb.connect()
con.register("Person", person)
return con.execute("""SELECT person_id, CONCAT(name, "(", SUBSTRING(profession, 1, 1), ")") AS name
FROM Person
ORDER BY person_id DESC;""").df()Complexity
| Measure | Complexity |
|---|---|
| Time | O(n log n) (typical) |
| Space | O(n) auxiliary |
Related problems
Frequently asked questions
- How hard is LeetCode 2504. Concatenate the Name and the Profession?
- LeetCode 2504. Concatenate the Name and the Profession is rated Easy on LeetCode.
- What topics does LeetCode 2504. Concatenate the Name and the Profession cover?
- LeetCode 2504. Concatenate the Name and the Profession is tagged Database on LeetCode.
- Is LeetCode 2504. Concatenate the Name and the Profession a premium problem?
- Yes. LeetCode 2504. Concatenate the Name and the Profession is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.