Database LeetCode Problems: All 249,
With Python Solutions

Every problem in this library that LeetCode tags Database. 33 of them carry a complete Python solution, a worked example and the time and space complexity of the approach.

Easy
100
Medium
105
Hard
44

Database problems by difficulty

Showing the first 200 of 249 problems. Problems with a complete Python solution are listed first, then by ascending problem number.

Easy (86)

Easy problems
No.Problem
0175Combine Two Tables
0181Employees Earning More Than Their Managers
0182Duplicate Emails
0183Customers Who Never Order
0196Delete Duplicate Emails
0197Rising Temperature
0511Game Play Analysis I
0577Employee Bonus
0584Find Customer Referee
0586Customer Placing the Largest Number of Orders
0595Big Countries
0596Classes With at Least 5 Students
0607Sales Person
0610Triangle Judgement
0619Biggest Single Number
0620Not Boring Movies
0627Swap Sex of Employees
1050Actors and Directors Who Cooperated At Least Three Times
1068Product Sales Analysis I
0512Game Play Analysis IIPremium
0597Friend Requests I: Overall Acceptance RatePremium
0603Consecutive Available SeatsPremium
0613Shortest Distance in a LinePremium
1069Product Sales Analysis IIPremium
1075Project Employees I
1076Project Employees IIPremium
1082Sales Analysis IPremium
1083Sales Analysis IIPremium
1084Sales Analysis III
1113Reported PostsPremium
1141User Activity for the Past 30 Days I
1142User Activity for the Past 30 Days IIPremium
1148Article Views I
1173Immediate Food Delivery IPremium
1179Reformat Department Table
1211Queries Quality and Percentage
1241Number of Comments per PostPremium
1251Average Selling Price
1280Students and Examinations
1294Weather Type in Each CountryPremium
1303Find the Team SizePremium
1322Ads PerformancePremium
1327List the Products Ordered in a Period
1350Students With Invalid DepartmentsPremium
1378Replace Employee ID With The Unique Identifier
1407Top Travellers
1421NPV QueriesPremium
1435Create a Session Bar ChartPremium
1484Group Sold Products By The Date
1495Friendly Movies Streamed Last MonthPremium
1511Customer Order FrequencyPremium
1517Find Users With Valid E-Mails
1527Patients With a Condition
1543Fix Product Name FormatPremium
1565Unique Orders and Customers Per MonthPremium
1571Warehouse ManagerPremium
1581Customer Who Visited but Did Not Make Any Transactions
1587Bank Account Summary II
1607Sellers With No SalesPremium
1623All Valid Triplets That Can Represent a CountryPremium
1633Percentage of Users Attended a Contest
1661Average Time of Process per Machine
1667Fix Names in a Table
1677Product's Worth Over InvoicesPremium
1683Invalid Tweets
1693Daily Leads and Partners
1729Find Followers Count
1731The Number of Employees Which Report to Each Employee
1741Find Total Time Spent by Each Employee
1757Recyclable and Low Fat Products
1777Product's Price for Each StorePremium
1789Primary Department for Each Employee
1795Rearrange Products Table
1809Ad-Free SessionsPremium
1821Find Customers With Positive Revenue this YearPremium
1853Convert Date FormatPremium
1873Calculate Special Bonus
1890The Latest Login in 2020
1939Users That Actively Request Confirmation MessagesPremium
1965Employees With Missing Information
1978Employees Whose Manager Left the Company
2026Low-Quality ProblemsPremium
2072The Winner UniversityPremium
2082The Number of Rich CustomersPremium
2205The Number of Users That Are Eligible for DiscountPremium
2230The Users That Are Eligible for DiscountPremium

Medium (82)

Medium problems
No.Problem
0176Second Highest Salary
0177Nth Highest Salary
0178Rank Scores
0180Consecutive Numbers
0184Department Highest Salary
0550Game Play Analysis IV
0570Managers with at Least 5 Direct Reports
0585Investments in 2016
0602Friend Requests II: Who Has the Most Friends
0608Tree Node
0626Exchange Seats
0534Game Play Analysis IIIPremium
0574Winning CandidatePremium
0578Get Highest Answer Rate QuestionPremium
0580Count Student Number in DepartmentsPremium
0612Shortest Distance in a PlanePremium
0614Second Degree FollowerPremium
1045Customers Who Bought All Products
1070Product Sales Analysis III
1077Project Employees IIIPremium
1098Unpopular BooksPremium
1107New Users Daily CountPremium
1112Highest Grade For Each StudentPremium
1126Active BusinessesPremium
1132Reported Posts IIPremium
1149Article Views IIPremium
1158Market Analysis I
1164Product Price at a Given Date
1174Immediate Food Delivery II
1193Monthly Transactions I
1204Last Person to Fit in the Bus
1205Monthly Transactions IIPremium
1212Team Scores in Football TournamentPremium
1264Page RecommendationsPremium
1270All People Report to the Given ManagerPremium
1285Find the Start and End Number of Continuous RangesPremium
1308Running Total for Different GendersPremium
1321Restaurant Growth
1341Movie Rating
1355Activity ParticipantsPremium
1364Number of Trusted Contacts of a CustomerPremium
1393Capital Gain/Loss
1398Customers Who Bought Products A and B but Not CPremium
1440Evaluate Boolean ExpressionPremium
1445Apples & OrangesPremium
1454Active UsersPremium
1459Rectangles AreaPremium
1468Calculate SalariesPremium
1501Countries You Can Safely Invest InPremium
1532The Most Recent Three OrdersPremium
1549The Most Recent Orders for Each ProductPremium
1555Bank Account SummaryPremium
1596The Most Frequently Ordered Products for Each CustomerPremium
1613Find the Missing IDsPremium
1699Number of Calls Between Two PersonsPremium
1709Biggest Window Between VisitsPremium
1715Count Apples and OrangesPremium
1747Leetflex Banned AccountsPremium
1783Grand Slam TitlesPremium
1811Find Interview CandidatesPremium
1831Maximum Transaction Each DayPremium
1841League StatisticsPremium
1843Suspicious Bank AccountsPremium
1867Orders With Maximum Quantity Above AveragePremium
1875Group Employees of the Same SalaryPremium
1907Count Salary Categories
1934Confirmation Rate
1949Strong FriendshipPremium
1951All the Pairs With the Maximum Number of Common FollowersPremium
1988Find Cutoff Score for Each SchoolPremium
1990Count the Number of ExperimentsPremium
2020Number of Accounts That Did Not StreamPremium
2041Accepted Candidates From the InterviewsPremium
2051The Category of Each Member in the StorePremium
2066Account BalancePremium
2084Drop Type 1 Orders for Customers With Type 0 OrdersPremium
2112The Airport With the Most TrafficPremium
2142The Number of Passengers in Each Bus IPremium
2159Order Two Columns IndependentlyPremium
2175The Change in Global RankingsPremium
2228Users With Two Purchases Within Seven DaysPremium
2238Number of Times a Driver Was a PassengerPremium

Hard (32)

Hard problems
No.Problem
0185Department Top Three Salaries
0262Trips and Users
0601Human Traffic of Stadium
0569Median Employee SalaryPremium
0571Find Median Given Frequency of NumbersPremium
0579Find Cumulative Salary of an EmployeePremium
0615Average Salary: Departments VS CompanyPremium
0618Students Report By GeographyPremium
1097Game Play Analysis VPremium
1127User Purchase PlatformPremium
1159Market Analysis IIPremium
1194Tournament WinnersPremium
1225Report Contiguous DatesPremium
1336Number of Transactions per VisitPremium
1369Get the Second Most Recent ActivityPremium
1384Total Sales Amount by YearPremium
1412Find the Quiet Students in All ExamsPremium
1479Sales by Day of the WeekPremium
1635Hopper Company Queries IPremium
1645Hopper Company Queries IIPremium
1651Hopper Company Queries IIIPremium
1767Find the Subtasks That Did Not ExecutePremium
1892Page Recommendations IIPremium
1917Leetcodify Friends RecommendationsPremium
1919Leetcodify Similar FriendsPremium
1972First and Last Call On the Same DayPremium
2004The Number of Seniors and Juniors to Join the CompanyPremium
2010The Number of Seniors and Juniors to Join the Company IIPremium
2118Build the EquationPremium
2153The Number of Passengers in Each Bus IIPremium
2173Longest Winning StreakPremium
2199Finding the Topic of Each PostPremium

Eyes only

When the Database problem arrives live.

In the live round, Stealth Interview reads the problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer says. It's a desktop app for macOS and Windows, invisible to screen sharing.