Skip to main content

LeetCode Problems by Category

A

B

C

D

Difference array

Difference arrays are not super common but are important to know as it is very difficult to derive on the spot in an interview. This method can be used when the input is a 2D array, where input[i] is in the format [left, right, value], or some equivalent form. The story behind the problem will usually be something along the lines of "between left and right there is value of something". Let's look at an example.

E

F

G

H

Hash table

  • LC 1. Two Sum

I

J

K

L

M

N

O

P

Prefix sum

If a problem's input is an array comprised of numeric elements and you find yourself needing to calculate multiple subarray sums, then consider building a prefix sum. But be mindful that a prefix sum costs O(n)O(n) space to build if the prefix sum is used in a "sliding" manner, then be on the lookout for space optimization possibilities by using a running sum and deducting that from the total sum for each iteration.

Q

R

S

Sliding window

If a problem has explicit constraints such as

  • sum greater than or less than k
  • limits on what is contained (such as maximum of k unique elements or no duplicates allowed)

and/or asks for

  • minimum or maximum length
  • minimum or maximum sum
  • number of subarrays/substrings

then think about a sliding window. Note that not all problems with these characteristics should be solved with a sliding window, and not all sliding window problems have these characteristics. These characteristics should only be used as a general guideline.

Clever endpoint trick

Fixed-width

Variable-width

Stacks

  • LC 20. Valid Parentheses
  • LC 682. Baseball Game
  • LC 155. Min Stack

T

Two pointers

U

V

W

X

Y

Z


SQL

Useful Reference

Summer 2021

Best problems

  • LC 586. Customer Placing the Largest Number of Orders
  • LC 601. Human Traffic of Stadium
  • LC 608. Tree Node
  • LC 615. Average Salary: Departments VS Company
  • LC 618. Students Report By Geography
  • LC 1045. Customers Who Bought All Products
  • LC 1126. Active Businesses
  • LC 1127. User Purchase Platform
  • LC 1159. Market Analysis II
  • LC 1179. Reformat Department Table
  • LC 1212. Team Scores in Football Tournament
  • LC 1225. Report Contiguous Dates
  • LC 1321. Restaurant Growth
  • LC 1341. Movie Rating
  • LC 1369. Get the Second Most Recent Activity
  • LC 1384. Total Sales Amount by Year
  • LC 1454. Active Users
  • LC 1468. Calculate Salaries
  • LC 1596. The Most Frequently Ordered Products for Each Customer
  • LC 1613. Find the Missing IDs
  • LC 1811. Find Interview Candidates

Good problems

Revisit

Beginner problems

  • LC 175. Combine Two Tables
  • LC 182. Duplicate Emails
  • LC 511. Game Play Analysis I
  • LC 577. Employee Bonus
  • LC 580. Count Student Number in Departments
  • LC 584. Find Customer Referee
  • LC 595. Big Countries
  • LC 620. Not Boring Movies
  • LC 1068. Product Sales Analysis I
  • LC 1069. Product Sales Analysis II
  • LC 1075. Project Employees I
  • LC 1113. Reported Posts
  • LC 1148. Article Views I
  • LC 1294. Weather Type in Each Country
  • LC 1327. List the Products Ordered in a Period
  • LC 1350. Students With Invalid Departments
  • LC 1378. Replace Employee ID With The Unique Identifier
  • LC 1407. Top Travellers
  • LC 1587. Bank Account Summary II
  • LC 1683. Invalid Tweets
  • LC 1693. Daily Leads and Partners
  • LC 1757. Recyclable and Low Fat Products
  • LC 1821. Find Customers With Positive Revenue this Year

CASE statements

Correlated subquery

Dates and timestamps

  • LC 197. Rising Temperature
  • LC 1084. Sales Analysis III
  • LC 1193. Monthly Transactions I
  • LC 1384. Total Sales Amount by Year
  • LC 1454. Active Users
  • LC 1543. Fix Product Name Format

DELETE

DISTINCT

  • LC 596. Classes More Than 5 Students
  • LC 1149. Article Views II

EXISTS and NOT EXISTS

Gaps and islands

  • LC 180. Consecutive Numbers
  • LC 601. Human Traffic of Stadium
  • LC 603. Consecutive Available Seats
  • LC 1225. Report Contiguous Dates
  • LC 1285. Find the Start and End Number of Continuous Ranges
  • LC 1454. Active Users

IN and NOT IN

Indicator variables

Joins

Cross-joins

LEFT JOIN

  • LC 175. Combine Two Tables
  • LC 183. Customers Who Never Order
  • LC 1158. Market Analysis I

Non-equi-joins

RIGHT JOIN

Self-joins

Median

NOT EXISTS (see EXISTS)

NOT IN (see IN)

NULL values and effective management

  • LC 176. Second Highest Salary
  • LC 584. Find Customer Referee
  • LC 608. Tree Node
  • LC 1098. Unpopular Books

Pivoting

Result set to multiple rows

Recursive CTEs

Regular expressions

Stored procedures

  • LC 177. Nth Highest Salary

UNION and UNION ALL

UPDATE

Window functions

Named windows

AVG()

COUNT()

DENSE_RANK()

  • LC 178. Rank Scores
  • LC 184. Department Highest Salary
  • LC 185. Department Top Three Salaries
  • LC 1341. Movie Rating

LAG()

LEAD()

MAX()

MIN()

PERCENTILE_CONT()

RANK()

ROW_NUMBER()

SUM()

With GROUP BY (ORDER BY aggregate)