leetcode.nsisong.com

LeetCode playbook

I keep short notes for every problem I solve. Explore the breakdowns, complexity calls, and the exact files that live in this repo.

Latest write-ups

MediumTypeScript
Wiggle Sort II

rearrange array in wiggle pattern (nums[0] < nums[1] > nums[2] < ...) using sorted interleaving.

arrayssortinggreedy
MediumPython
Unique Paths II

count paths from top-left to bottom-right with obstacles using dp with space optimization to O(n).

dynamic-programmingmatrix
UnknownC++, Java
Walking Robot Simulation

quick reference for walking robot simulation. more notes soon.

c++java
MediumTypeScript
Largest Plus Sign

find the largest plus sign order by computing longest consecutive 1s in four directions using dp.

dynamic-programmingmatrix
UnknownSQL
Movie Rating

quick reference for movie rating. more notes soon.

sql
HardPython
Zuma Game

find minimum balls needed to clear board using dfs with memoization, trying to form groups of 3+.

dfsbacktrackingmemoization
UnknownTypeScript
Game Theory

quick reference for game theory. more notes soon.

typescript
HardPHP
Max Points on a Line

find maximum number of points that lie on the same line using slope calculation and hash map.

hash-tablemathgeometry
HardPython
Candy

distribute candy to children based on ratings using two-pass greedy approach.

greedyarrays
EasyC
Number of Recent Calls

implement RecentCounter using circular queue to count requests within last 3000ms.

queuedesign
HardPHP
Largest Palindrome Product

find the largest palindrome made from the product of two n-digit numbers using brute force with optimizations.

mathbrute-force
MediumPHP
Maximal Square

find the largest square of 1s in a binary matrix using dynamic programming.

dynamic-programmingmatrix
HardTypeScript
Split Array Largest Sum

find minimum largest sum when splitting array into k subarrays using binary search on answer.

binary-searchgreedyarrays
UnknownScala
Special Array I

quick reference for special array i. more notes soon.

scala
HardTypeScript
LFU Cache

implement least frequently used cache with O(1) operations using hash maps and doubly linked lists.

designhash-tablelinked-list
HardPython
Word Ladder

find shortest transformation sequence from beginWord to endWord using bfs.

bfsgraphstring
MediumTypeScript
Search a 2D Matrix

binary search on a sorted 2d matrix by treating it as a flattened sorted array.

binary-searchmatrixarrays
HardPython
Palindrome Pairs

find all pairs of words that form palindrome when concatenated by checking all prefix/suffix splits.

hash-tablestringtrie
HardPython
Sliding Window Median

find median for each sliding window using sorted list to maintain window in sorted order.

sliding-windowheapsorted-list
UnknownPHP
Addtwonumbers

quick reference for addtwonumbers. more notes soon.

php
HardPHP
Valid Number

validate if string represents a valid number using state machine or regex.

stringstate-machine
MediumC
Set Matrix Zeroes

set entire row and column to zero when element is zero, using first row and column as markers for O(1) space.

matrixarrays
HardTypeScript
Stamping the Grid

check if a grid can be fully covered by stamps using prefix sums and 2d difference array.

prefix-summatrixgreedy
HardPHP
Number of Digit One

count total number of digit 1 appearing in all numbers from 1 to n using digit dp or mathematical analysis.

mathdynamic-programming
HardPHP
Strong Password Checker

find minimum steps to make password strong by handling length, character types, and repeating sequences.

greedystring
UnknownPython
Candy

quick reference for candy. more notes soon.

python
UnknownErlang, PHP
Contains Duplicate 3

quick reference for contains duplicate 3. more notes soon.

erlangphp
UnknownPHP
Count Of Range Sum

quick reference for count of range sum. more notes soon.

php
UnknownTypeScript
Design Neighbor Sum Service

quick reference for design neighbor sum service. more notes soon.

typescript
UnknownPHP
First Missing Positive

quick reference for first missing positive. more notes soon.

php
UnknownTypeScript
Largest Plus Sign

quick reference for largest plus sign. more notes soon.

typescript
UnknownTypeScript
Magic Squares In Grid

quick reference for magic squares in grid. more notes soon.

typescript
UnknownPHP
Max Points On Line

quick reference for max points on line. more notes soon.

php
UnknownPHP
Maximal Square

quick reference for maximal square. more notes soon.

php
UnknownTypeScript
Maximum Sum Of An Hourglass

quick reference for maximum sum of an hourglass. more notes soon.

typescript
UnknownErlang, PHP
Median Of Two Sorted Arrays

quick reference for median of two sorted arrays. more notes soon.

erlangphp
UnknownPython
Minimum Path Sum

quick reference for minimum path sum. more notes soon.

python
UnknownPHP
Number Of Digit One

quick reference for number of digit one. more notes soon.

php
UnknownPython
Palindrome Pairs

quick reference for palindrome pairs. more notes soon.

python
UnknownPython
Reverse Pairs

quick reference for reverse pairs. more notes soon.

python
UnknownPHP
Russian Doll Envelopes

quick reference for russian doll envelopes. more notes soon.

php
UnknownTypeScript
Search A 2d Matrix

quick reference for search a 2d matrix. more notes soon.

typescript
UnknownC
Set Matrix Zeroes

quick reference for set matrix zeroes. more notes soon.

c
UnknownTypeScript
Simplify Path

quick reference for simplify path. more notes soon.

typescript
UnknownPython
Sliding Window Median

quick reference for sliding window median. more notes soon.

python
UnknownTypeScript
Stamping The Grid

quick reference for stamping the grid. more notes soon.

typescript
UnknownPHP
Strong Password Checker

quick reference for strong password checker. more notes soon.

php
UnknownPython
Two Sum

quick reference for two sum. more notes soon.

python
UnknownPython
Unique Paths Ii

quick reference for unique paths ii. more notes soon.

python
UnknownPHP
Valid Number

quick reference for valid number. more notes soon.

php
UnknownTypeScript
Wiggle Sort Ii

quick reference for wiggle sort ii. more notes soon.

typescript
UnknownErlang, PHP
Wildcard Matching

quick reference for wildcard matching. more notes soon.

erlangphp
UnknownPython
Word Ladder

quick reference for word ladder. more notes soon.

python
UnknownErlang, PHP
Word Ladder 2

quick reference for word ladder 2. more notes soon.

erlangphp
UnknownPython
Zuma Game

quick reference for zuma game. more notes soon.

python
HardPHP
Word Ladder II

find all shortest transformation sequences from beginWord to endWord using bfs with path tracking.

bfsbacktrackinggraph
UnknownPython
Insertion Sort List

quick reference for insertion sort list. more notes soon.

python
MediumTypeScript
Maximum Sum of an Hourglass

Sliding a fixed hourglass mask through the grid and tracking the best sum with constant-time updates.

arraysprefix-sumgrid
MediumTypeScript
Maximize Area of Square Hole in Grid

Binary search on the side length of the square holes while counting rails removed along each axis.

binary-searchsortinggreedy
MediumTypeScript
String Compression

compress string in-place by replacing consecutive characters with character and count using two pointers.

two-pointersstring
UnknownPython
Select Data

quick reference for select data. more notes soon.

python
HardPython
Perfect Rectangle

check if rectangles form exact rectangle without gaps or overlaps using corner counting and area validation.

geometryhashing
MediumTypeScript
Magic Squares in Grid

Check every 3×3 window for the 1..9 magic square pattern using center and parity pruning.

gridbrute-forcehashing
UnknownC++
Largest Magic Square

quick reference for largest magic square. more notes soon.

c++
HardTypeScript
Frog Jump

determine if a frog can cross a river using dfs with memoization, tracking position and last jump distance.

dynamic-programmingdfsmemoization
HardPHP
Regular Expression Matching

match string against pattern with . and * using dynamic programming with memoization.

dynamic-programmingstring
HardPHP
Contains Duplicate III

check if there exist two indices with value difference ≤ valueDiff and index difference ≤ indexDiff using sliding window with sorted array.

sliding-windowbinary-searcharrays
UnknownPython
leetcode intro

overview of my leetcode writeups and plan

math
UnknownPython
basic calculator

basic calculator

stringstackmathrecursion
UnknownPython
skyline problem

skyline problem

treequeuesortingheap
UnknownPython
shortest palindrome

shortest palindrome

arraytwo-pointersstringbacktrackingdesign
MediumPython
3sum

3sum

arraytwo-pointers
MediumPython
combination sum

combination sum

arraybacktracking
MediumPython
permutations

permutations

arraybacktracking
MediumPython
group anagrams

group anagrams

hash-tablestring
MediumPython
maximum subarray

maximum subarray

arraydynamic-programming
UnknownPython
48 my leetcode journey

48 my leetcode journey

arrayhash-tablelinked-listtwo-pointersstring
HardJavaScript
burst balloons

burst balloons

arraystringdynamic-programmingbacktrackinggreedy
HardPython
patching array

patching array

arraybinary-searchdynamic-programmingbacktrackinggreedy
HardPython
Reverse Pairs

count pairs where nums[i] > 2 * nums[j] and i < j using merge sort with counting during merge phase.

divide-and-conquermerge-sort
MediumTypeScript
Design Neighbor Sum Service

design a service to compute sums of adjacent and diagonal neighbors using prefix sums and linear search.

designmatrixprefix-sum
HardPHP
Count of Range Sum

count subarrays with sum in range [lower, upper] using prefix sums and merge sort counting.

divide-and-conquerprefix-summerge-sort
HardPHP
Wildcard Matching

match string against pattern with ? and * using dynamic programming.

dynamic-programmingstringgreedy
MediumPython
Minimum Path Sum

find minimum sum path from top-left to bottom-right using dynamic programming with space optimization.

dynamic-programmingmatrix
UnknownC++
Sort List

quick reference for sort list. more notes soon.

c++
MediumPython
Building H2O

coordinate hydrogen and oxygen threads to form water molecules using semaphores and barrier synchronization.

concurrencythreading
EasyPython
Two Sum

find two indices whose values sum to target using hash map for O(n) lookup.

hash-tablearrays
HardPHP
First Missing Positive

find the smallest missing positive integer using array as hash table by placing each number at its correct index.

arrayshashing
HardC
Trapping Rain Water II

calculate trapped rainwater in 2d elevation map using min heap starting from boundary cells.

heapbfsmatrix
UnknownPython
Sort Colors

quick reference for sort colors. more notes soon.

python
UnknownGo
Matrix Block Sum

quick reference for matrix block sum. more notes soon.

go
HardPHP
Russian Doll Envelopes

find maximum number of envelopes that can be nested using longest increasing subsequence on sorted envelopes.

dynamic-programmingbinary-searchsorting
MediumTypeScript
Simplify Path

normalize unix-style file paths by handling . and .. components using a stack.

stackstring