Replace Employee ID With The Unique Identifier — LeetCode 1378 Python Solution

EasyDatabase
Problem
#1378
Reading time
2 min

Table schema

SQL
Table: Employees +---------------+---------+ | Column Name | Type | +---------------+---------+ | id | int | | name | varchar | +---------------+---------+ id is the primary key (column with unique values) for this table. Each row of this table contains the id and the name of an employee in a company.

Example

SQL
+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| id            | int     |
| name          | varchar |
+---------------+---------+
id is the primary key (column with unique values) for this table.
Each row of this table contains the id and the name of an employee in a company.

Python solution

Python
import duckdb
import pandas as pd

def solution(employees: pd.DataFrame, employee_uni: pd.DataFrame) -> pd.DataFrame:
    con = duckdb.connect()
    con.register("Employees", employees)
    con.register("EmployeeUNI", employee_uni)
    return con.execute("""SELECT unique_id, name
FROM
    Employees
    LEFT JOIN EmployeeUNI USING (id);""").df()

Complexity

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

Related problems

Frequently asked questions

How hard is LeetCode 1378. Replace Employee ID With The Unique Identifier?
LeetCode 1378. Replace Employee ID With The Unique Identifier is rated Easy on LeetCode.
What topics does LeetCode 1378. Replace Employee ID With The Unique Identifier cover?
LeetCode 1378. Replace Employee ID With The Unique Identifier is tagged Database on LeetCode.

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