Algorithms
Problems
474 problems grouped by topic. Every ladder starts simple and builds to hard, so the next problem is always within reach.
0 of 474 solved
Browse topics 27 sections · Jump to a section
Problems
Arrays and Matrix0 / 2121⌄
1Array Length and EndsFree2Sum Array ElementsFree3Count Target OccurrencesFree4Find Largest ValueFree5Second Largest Distinct ValueFree6Running Sum7Greatest to the Right8Product Except Self9In Place Reversal10Remove Element11Rotate Array Right12Matrix Dimensions13Matrix Row Sums14Transpose Matrix15Toeplitz Matrix16Main Diagonal Sum17Spiral Matrix Traversal18Rotate Square Matrix19Set Matrix Zeroes20Game of Life In Place21Recommend Movies
String and Array0 / 1818⌄
25String Length and EndsFree26Count Character OccurrencesFree27Build Reversed StringFree28Reverse Character ArrayFree29Reverse Each WordFree30Reverse Word Order31Valid Palindrome32Palindrome After One Deletion33Longest Common Prefix34Run-Length Encode35In-Place String Compression36First Substring Match37Count Overlapping Matches38Find the Difference39Is Subsequence40Trim Matching Ends41String to Integer (atoi)42Valid Number★
Hash Maps and Sets0 / 3333⌄
45Contains Duplicate46Is Unique47Find the Duplicate Number48Nearby Duplicate49Maximum Gap★50Nearby Almost Duplicate★51First Unique Character52Valid Anagram53Ransom Note54Palindrome Permutation55Longest Buildable Palindrome56Find Common Characters57Bulls and Cows58Shared Sorted Values59Intersection Unique60Intersection with Multiplicity61Two Sum Indices62Earliest Complement Pairs63Digit Pair Spacing Check64K-diff Pairs in an Array65Count Good Meals664Sum II67Brick Wall68Longest Consecutive Sequence69Group Anagrams70Equal Row and Column Pairs71Valid Sudoku72Top K Frequent Elements73Sort Characters by Frequency74Isomorphic Strings75Word Pattern76Find and Replace Pattern77Roman to Integer
Simple Sorting0 / 1818⌄
651Already In Order?652Count the Drops653Smallest to the Front654Selection Sort From Scratch655Bubble Sort From Scratch656How Many Sweeps?657Total Swaps to Sort658Insertion Sort From Scratch659Slot One Value In660Sort Largest First661Second Smallest Value662K-th Smallest663Merge Two Sorted Arrays664Evens Before Odds665Sort Small Non-Negative Ints666Sort Three Colors667Squares of a Sorted Array668Sort by How Often
Sorting0 / 1515⌄
78Sort an Array79Count Inversions★80Partition Around a Pivot81Implement Quickselect82Multi-Field Sort83Relative Sort Array84Sort by Frequency85Largest Concatenated Number86Meeting Rooms Feasibility87Merge Overlapping Intervals88Insert Interval89Remove Covered Intervals90Minimum Meeting Rooms91Fewest Arrows for Balloons92Wiggle Sort
Binary Search0 / 1414⌄
93Linear Search in a Sorted Array94Binary Search95Search Insert Position96First Bad Version97Find First and Last Position in Sorted Array98Search in Rotated Sorted Array99Find Minimum in Rotated Sorted Array100Sqrt(x)101Koko Eating Bananas102Capacity to Ship Packages Within D Days103Kth Merged Element★104Median of Two Sorted Arrays★105Magic Index106Search a 2D Matrix
Two Pointers0 / 2727⌄
107Two Sum in Sorted Array108Unique Two Sum Pairs109Closest Pair Sum110Count Pairs Under Target111Count Pairs Over Target112Pair Sums in Range113Smallest Difference Across Arrays114Merge Sorted Arrays115Cross-Array Two Sum116Backward In-Place Merge117Remove Duplicates Sorted Array118At Most Two Duplicates119Move Zeroes120Sort Array By Parity121Sort Colors122Squares of Sorted Array123Container With Most Water124Trapping Rain Water★125Three Sum Unique Triplets126Three Sum Closest127Count Triplets Below Target128Four Sum Unique Quadruplets129Backspace String Compare130Linked List Cycle131Circular Array Loop132Two Sum Data Structure133Sub Sort
Stacks and Queues0 / 2525⌄
134Bracket Matcher135Validate Parentheses136Minimum Add for Valid Parentheses137Minimum Remove for Valid Parentheses138Evaluate Reverse Polish Notation139Basic Calculator★140Simplify Unix Path141Nested Ternary Evaluator142Decode Repetition String143Prices After Discounts144Asteroid Collision145Remove K Adjacent Duplicates146Smallest Subsequence of Distinct Characters147Exclusive Time of Functions148Baseball Game149Score of Parentheses150Folder Navigation Log151Ticket Queue Timing152Students Left Without Lunch153Dota2 Senate154Moving Average from Data Stream155Recent Request Counter156First Nonrepeating Character Stream157Iterative Flood Fill158Level Order with Queue
Linked Lists0 / 1919⌄
669Length of a Linked List670Sum of a Linked List671Value at Position N672Largest Value in a List673Append a Node674Insert Before a Position675Delete the First Match676Drop Sorted Duplicates677Reverse a Linked List678Middle of the List679N-th Node From the End680Remove N-th From the End681Is the List a Palindrome?682Partition Around a Value683Group Odd and Even Positions684Swap Every Two Nodes685Rotate the List Right686Merge Two Sorted Lists687Add Two Numbers★
Trees and Binary Search Trees0 / 1818⌄
688In-Order Values689How Many Nodes690Height of the Tree691Sum of All Nodes692Count the Leaves693Values by Level694Right-Side View695Is It Height-Balanced?696Symmetric Tree?697Invert a Binary Tree698Path Sum Exists?699Valid Binary Search Tree?700Search a BST701Range Sum of a BST702K-th Smallest in a BST703Lowest Common Ancestor in a BST704Insert Into a BST705Sorted Array to Balanced BST★
Recursion and Backtracking0 / 99⌄
Monotonic Stacks0 / 77⌄
Heaps and Priority Queues0 / 1717⌄
182Kth Largest Element183Kth Largest in a Stream184K Closest Points185Top K Frequent Words186Merge K Sorted Arrays187Kth Smallest in a Sorted Matrix188Find K Pairs with Smallest Sums189Smallest Range Covering K Lists★191Sliding Window Median★192Smallest Number in Infinite Set193Minimum Cost to Connect Sticks194Task Scheduler195Reorganize String196Per-Task Cooldown Scheduling★197IPO Capital Maximization★198Seat Reservation Manager199Twitter Feed Design★
Sliding Window0 / 2020⌄
200Defuse the Bomb201Distinct Window Max Sum202Maximum Average Subarray I203Vowels per Window204Count Fixed-Length Target Windows205Distinct Count per Window206Permutation in String207Longest Substring Without Repeats209Longest Repeating Character Replacement210Frequency at Most K211Longest Ones After K Flips212Subarrays with K Distinct★213Binary Subarrays to Goal214Shortest Sum-at-Least Window215Count Product Below K216Minimum Window Substring★217Minimum Window Subsequence★218Find All Anagram Starts219Longest Window within Budget★222Shortest K-Sum Subarray★
Subarrays and Prefix Sums0 / 1616⌄
220Left and Right Sum Differences224Range Addition Array226Longest Subarray Sum K227Subarray Sum Divisible by K228Continuous Multiple of K229Balanced Zeros and Ones230Subarrays with K Odds231Maximum Subarray Sum232Maximum Circular Subarray233Maximum Product Subarray234Count Range Sum★2352D Prefix Sum Queries236Count Submatrices Sum Target★237Maximum Sum Rectangle No Larger Than K★238Corporate Flight Bookings239Median-K Subarray Count★
Greedy Algorithms0 / 1414⌄
243Assign Cookies244Boats to Save People245Bag of Tokens246Lemonade Change247Can Place Flowers248Gas Station Circuit249Jump Game250Jump Game II251Non-overlapping Intervals252Partition Labels253Candy Distribution★254Queue Reconstruction by Height255Stack-Robot Smallest String256Maximum Average Pass Ratio
Graphs I — Fundamentals0 / 1212⌄
258Find Center of Star Graph259Reachability Between Vertices257Uniform-Edge Shortest Reach260All Paths from Source to Target261Count Connected Components262Count Unreachable Vertex Pairs263Keys and Rooms264Graph Valid Tree265Clone Graph293Is Graph Bipartite294Possible Bipartition295Evaluate Division
Graphs II — Grid Graphs0 / 1313⌄
Graphs III — Search and Applications0 / 2020⌄
277Toroidal Nearest Enemy278Shortest Path in Binary Matrix279Nearest Exit from Maze280Shortest Path with Obstacle Eliminations★281Rotting Oranges28201 Matrix Distances283Walls and Gates284Farthest Water from Land285Shortest Distance from All Buildings★288Minimum Genetic Mutation289Open the Lock290Snakes and Ladders286Word Ladder Length★287Word Ladder Paths★291Bus Routes★298Detonate Maximum Bombs296Shortest Alternating Paths297Minimum Edge Reversals to Reach All Nodes299Valid Arrangement of Pairs★300Reconstruct Itinerary★
Topological Sort0 / 1313⌄
303Build Order304Course Schedule Feasibility305Course Schedule Order306Alien Dictionary★307Sequence Reconstruction308Minimum Semesters309Course Duration Critical Path★310Recipes from Supplies311Largest Color Value in Directed Graph★312Eventual Safe Nodes313Find All Ancestors in DAG314Minimum Height Tree Roots315Sort Items by Groups★
Dynamic Programming I — Foundations0 / 1919⌄
316Fibonacci Number317Tribonacci Number318Climbing Stairs319Custom-Step Stair Climb320Min Cost Climbing Stairs321Robot in a Grid322Domino and Tromino Tiling323House Robber324House Robber Circular325Delete and Earn326House Robber Tree327Decode Ways328Decode Ways with Wildcards★329Word Break330Word Break II★331Coin Change Minimum332Coin Change Combinations333Combination Sum IV334Perfect Squares
Dynamic Programming II — Grid DP0 / 1212⌄
341Unique Paths342Unique Paths with Obstacles343Unique Paths III★344Minimum Path Sum345Minimum Falling Path Sum346Triangle Minimum Total347Minimum Survival Health★348Maximal Square349Count Square Submatrices350Count Submatrices With All Ones351Longest Increasing Path Matrix★352Two-Robot Cherry Harvest★
Dynamic Programming III — Strings and Palindromes0 / 1515⌄
353Longest Common Subsequence354Reconstruct the Longest Common Subsequence355Longest Common Substring356Extract the Longest Common Substring357Distinct Subsequences★358Shortest Common Supersequence★359Edit Distance★360Interleaving String361Longest Palindromic Subsequence362Minimum Insertions Palindrome363Count Palindromic Substrings364Longest Palindromic Substring365Palindrome Partition Minimum Cuts★366Partition String into Palindromes367Palindrome Partition III★
Dynamic Programming IV — Knapsack, Intervals and Games0 / 1414⌄
335Partition Equal Subset Sum336Last Stone Weight II337Target Sum Ways338Ones and Zeroes339Partition to K Equal Subsets★340Profitable Schemes★368Matrix Chain Multiplication★369Minimum Cost Cut Stick★370Burst Balloons★371Boolean Evaluation★372Stone Game373Predict the Winner374Stone Game II★375Pizza Slices★
Dynamic Programming V — Sequences, Scheduling and Stocks0 / 2020⌄
376Longest Increasing Subsequence377Count Longest Increasing Subsequences378Russian Doll Envelopes★379Largest Divisible Subset380Longest Arithmetic Subsequence381Arithmetic Slices382Longest Fibonacci-like Subsequence383Maximum Profit Job Scheduling★384Maximum Length Pair Chain385Partition Array for Maximum Sum386Minimum Difficulty Job Schedule★387Split Array Largest Sum★388Rod Cutting389Egg Drop★390Super Egg Drop★391Best Time to Buy and Sell Stock392Best Time to Buy and Sell Stock II393Best Time to Buy and Sell Stock with Cooldown394Best Time to Buy and Sell Stock with Transaction Fee395Best Time to Buy and Sell Stock IV★
Dynamic Programming VI — State Machines, Trees and Patterns0 / 1313⌄
Miscellaneous0 / 3232⌄
43Valid Parentheses44Longest Valid Parentheses★168Next Greater Element I169Next Greater Element Circular170Daily Temperatures171Buildings With an Ocean View172Stock Span175Sum of Subarray Minimums181Last Stone Weight190Find Median from Data Stream★208Fruit Into Baskets221Immutable Range Sum Queries223Pivot Index225Count Subarrays Sum K240Sliding Window Maximum★241Constrained Subsequence Sum★242Longest Subarray Max-Min Within Limit★409Reshape Matrix410Generate Spiral Matrix411Diagonal Traverse412Count Primes413Largest Four414Single Number415Missing Number416Majority Element417Majority Elements over One Third418Find All Duplicates in an Array419Find All Missing Values420Number Stream421Text Justification★422Palindrome Pairs★292Course Schedule