Data structures & algorithms, drawn so they click
Every algorithm becomes something you already know: two friends walking toward each other along a row of lockers, a librarian halving a shelf, a stamp collector spotting a repeat. Watch each one move step by step next to its Python code, then type your own input and watch it run again.
12 core patterns150 / 150 NeetCode problems61 extra practice problemsPython
Start here: the 12 core patterns
Most interview problems are a twist on one of these. Learn the picture once and you’ll recognise it everywhere.
- Pattern 1Two pointersTwo friends, one row of lockers
- Pattern 2Sliding windowA train window passing houses
- Pattern 3Binary searchFinding a book on a sorted shelf
- Pattern 4StackMatching brackets with a stack of plates
- Pattern 5Queue · BFSRipples across a pond
- Pattern 6HashingThe coat check counter
- Pattern 7Recursion · DPCounting ways up a staircase
- Pattern 8GreedyPaying with the biggest coin that fits
- Pattern 9Linked listRecoupling a train backwards
- Pattern 10Trees · DFSWalking a folder tree
- Pattern 11HeapHospital triage: most urgent first
- Pattern 12GraphsFastest route across the city
NeetCode 150, by topic
The well-known NeetCode 150 list in its roadmap order. Every problem has a picture, the key idea, Python code and a step-by-step animation. Mark problems solved or flag them for review; progress is saved in this browser and shared with the animated app. Revising? Use the revision cards.
Arrays & Hashing · 9
- LeetCode 217 · EasyContains DuplicateA stamp collector spots a repeat
- LeetCode 242 · EasyValid AnagramTwo bags of letter tiles
- LeetCode 1 · EasyTwo SumThe coat check counter
- LeetCode 49 · MediumGroup AnagramsSorting words into jars by their letters
- LeetCode 347 · MediumTop K Frequent ElementsThe k most frequent visitors
- LeetCode 271 · MediumEncode and Decode StringsParcels on a conveyor, each with a length label
- LeetCode 238 · MediumProduct of Array Except SelfTwo runners multiplying from each end
- LeetCode 36 · MediumValid SudokuThree checklists for a Sudoku board
- LeetCode 128 · MediumLongest Consecutive SequenceBeads on a ruler
Two Pointers · 5
- LeetCode 125 · EasyValid PalindromeReading a sign from both ends
- LeetCode 167 · MediumTwo Sum IITwo friends, one row of lockers
- LeetCode 15 · Medium3SumThree lockers that cancel out
- LeetCode 11 · MediumContainer With Most WaterTwo fence posts holding water
- LeetCode 42 · HardTrapping Rain WaterRain pooling between buildings
Sliding Window · 6
- LeetCode 121 · EasyBest Time to Buy and Sell StockBuying the dip on a price chart
- LeetCode 3 · MediumLongest Substring Without Repeating CharactersA train window over shop signs
- LeetCode 424 · MediumLongest Repeating Character ReplacementRepainting a few fence planks
- LeetCode 567 · MediumPermutation in StringA letter stencil sliding along a strip
- LeetCode 76 · HardMinimum Window SubstringThe smallest net that catches every fish
- LeetCode 239 · HardSliding Window MaximumThe tallest tower in view from a train
Stack · 7
- LeetCode 20 · EasyValid ParenthesesMatching brackets with a stack of plates
- LeetCode 155 · MediumMin StackPlates with a sticky note for the lightest
- LeetCode 150 · MediumEvaluate Reverse Polish NotationA calculator built from plates
- LeetCode 22 · MediumGenerate ParenthesesStacking cups that open and close
- LeetCode 739 · MediumDaily TemperaturesWaiting for a warmer day
- LeetCode 853 · MediumCar FleetCars bunching into convoys on a one-lane road
- LeetCode 84 · HardLargest Rectangle in HistogramThe biggest billboard on a skyline
Binary Search · 7
- LeetCode 704 · EasyBinary SearchFinding a book on a sorted shelf
- LeetCode 74 · MediumSearch a 2D MatrixAn elevator that searches a sorted apartment block
- LeetCode 875 · MediumKoko Eating BananasFinding the slowest eating speed that still works
- LeetCode 153 · MediumFind Minimum in Rotated Sorted ArrayA clock face someone turned
- LeetCode 33 · MediumSearch in Rotated Sorted ArrayFinding a number on a turned clock face
- LeetCode 981 · MediumTime Based Key-Value StoreA diary that answers “what was it at time t?”
- LeetCode 4 · HardMedian of Two Sorted ArraysCutting two sorted shelves in half together
Linked List · 11
- LeetCode 206 · EasyReverse Linked ListRecoupling a train backwards
- LeetCode 21 · EasyMerge Two Sorted ListsTwo sorted trains meeting at a junction
- LeetCode 143 · MediumReorder ListZipping the front of a train with its back
- LeetCode 19 · MediumRemove Nth Node From End of ListTwo inspectors, n coaches apart
- LeetCode 138 · MediumCopy List with Random PointerPhotocopying a train with buddy links
- LeetCode 2 · MediumAdd Two NumbersTwo odometer trains, digit by digit
- LeetCode 141 · EasyLinked List CycleTortoise and hare on a looping track
- LeetCode 287 · MediumFind the Duplicate NumberBoxes with notes pointing to other boxes
- LeetCode 146 · MediumLRU CacheA small hotel that evicts the guest who’s been idle longest
- LeetCode 23 · HardMerge k Sorted ListsA dispatcher merging trains from k tracks
- LeetCode 25 · HardReverse Nodes in k-GroupReversing the train k coaches at a time
Trees · 15
- LeetCode 226 · EasyInvert Binary TreeFlipping a mobile in a mirror
- LeetCode 104 · EasyMaximum Depth of Binary TreeHow deep does the folder tree go?
- LeetCode 543 · EasyDiameter of Binary TreeThe longest walk between two leaves
- LeetCode 110 · EasyBalanced Binary TreeIs the hanging mobile balanced?
- LeetCode 100 · EasySame TreeTwo gardeners comparing their trees
- LeetCode 572 · EasySubtree of Another TreeSpotting a small branch pattern inside a big tree
- LeetCode 235 · MediumLowest Common Ancestor of a Binary Search TreeWhere two relatives’ family lines split
- LeetCode 102 · MediumBinary Tree Level Order TraversalA family photo, one generation per row
- LeetCode 199 · MediumBinary Tree Right Side ViewWhat you see standing to the right of the tree
- LeetCode 1448 · MediumCount Good Nodes in Binary TreeA hiker counting viewpoints with no taller peak behind
- LeetCode 98 · MediumValidate Binary Search TreeEvery branch has a fence of allowed values
- LeetCode 230 · MediumKth Smallest Element in a BSTCounting library shelves in order
- LeetCode 105 · MediumConstruct Binary Tree from Preorder and Inorder TraversalRebuilding a family tree from two lists
- LeetCode 124 · HardBinary Tree Maximum Path SumThe richest trail through a tree of coins
- LeetCode 297 · HardSerialize and Deserialize Binary TreePacking a tree into a parcel tape and unpacking it
Tries · 3
Heap / Priority Queue · 7
- LeetCode 703 · EasyKth Largest Element in a StreamA podium with k places as scores keep arriving
- LeetCode 1046 · EasyLast Stone WeightSmashing the two heaviest rocks together
- LeetCode 973 · MediumK Closest Points to OriginThe k cafés nearest your home
- LeetCode 215 · MediumKth Largest Element in an ArrayA podium that only keeps the top k
- LeetCode 621 · MediumTask SchedulerA chef whose stations need time to cool down
- LeetCode 355 · MediumDesign TwitterA news feed merged from the people you follow
- LeetCode 295 · HardFind Median from Data StreamTwo waiting rooms with the median at the door
Backtracking · 9
- LeetCode 78 · MediumSubsetsPizza toppings: take it or leave it
- LeetCode 39 · MediumCombination SumFilling a piggy bank with reusable coins
- LeetCode 46 · MediumPermutationsEvery way to seat guests in a row of chairs
- LeetCode 90 · MediumSubsets IIToppings with duplicates, no repeated pizzas
- LeetCode 40 · MediumCombination Sum IIEach coin used once, no repeated handfuls
- LeetCode 79 · MediumWord SearchTracing a word through a letter grid
- LeetCode 131 · MediumPalindrome PartitioningCutting a ribbon only at mirror points
- LeetCode 17 · MediumLetter Combinations of a Phone NumberTyping on an old phone keypad
- LeetCode 51 · HardN-QueensPlacing queens that can’t attack each other
Graphs · 13
- LeetCode 200 · MediumNumber of IslandsPainting islands on a sea chart
- LeetCode 133 · MediumClone GraphPhotocopying a city map junction by junction
- LeetCode 695 · MediumMax Area of IslandMeasuring the biggest island
- LeetCode 417 · MediumPacific Atlantic Water FlowRain on an island draining to two oceans
- LeetCode 130 · MediumSurrounded RegionsCapturing surrounded stones on a Go board
- LeetCode 994 · MediumRotting OrangesRot spreading through a fruit crate
- LeetCode 286 · MediumWalls and GatesDistance from every room to the nearest exit
- LeetCode 207 · MediumCourse ScheduleCan every course be taken?
- LeetCode 210 · MediumCourse Schedule IIA timetable that respects every prerequisite
- LeetCode 684 · MediumRedundant ConnectionThe one cable too many
- LeetCode 323 · MediumNumber of Connected Components in an Undirected GraphCounting circles of friends
- LeetCode 261 · MediumGraph Valid TreeIs this network a tree?
- LeetCode 127 · HardWord LadderChanging one letter at a time
Advanced Graphs · 6
- LeetCode 332 · HardReconstruct ItineraryUsing every plane ticket exactly once
- LeetCode 1584 · MediumMin Cost to Connect All PointsLaying the cheapest cables between houses
- LeetCode 743 · MediumDijkstraFastest route across the city
- LeetCode 778 · HardSwim in Rising WaterWaiting for the flood to let you swim across
- LeetCode 269 · HardAlien DictionaryWorking out an alien alphabet from a sorted word list
- LeetCode 787 · MediumCheapest Flights Within K StopsThe cheapest trip with a limited number of layovers
1-D DP · 12
- LeetCode 70 · EasyClimbing StairsCounting ways up a staircase
- LeetCode 746 · EasyMin Cost Climbing StairsA staircase with a toll on every step
- LeetCode 198 · MediumHouse RobberA burglar who can’t hit two neighbours
- LeetCode 213 · MediumHouse Robber IIHouses around a roundabout
- LeetCode 5 · MediumLongest Palindromic SubstringA mirror sliding along the letters
- LeetCode 647 · MediumPalindromic SubstringsCounting every mirror image hidden in a word
- LeetCode 91 · MediumDecode WaysHow many ways to read a secret number code
- LeetCode 322 · MediumCoin ChangeFewest coins when greedy fails
- LeetCode 152 · MediumMaximum Product SubarrayMultipliers where a minus sign flips everything
- LeetCode 139 · MediumWord BreakSnapping word tiles onto a sentence strip
- LeetCode 300 · MediumLongest Increasing SubsequenceDealing cards into patience piles
- LeetCode 416 · MediumPartition Equal Subset SumCan a pile of weights balance on a scale?
2-D DP · 11
- LeetCode 62 · MediumUnique PathsA delivery robot that only goes right or down
- LeetCode 1143 · MediumLongest Common SubsequenceMatching two DNA strands
- LeetCode 309 · MediumBest Time to Buy and Sell Stock with CooldownA trader with three moods: holding, just sold, resting
- LeetCode 518 · MediumCoin Change IICounting the ways to make change
- LeetCode 494 · MediumTarget SumPlus or minus: walking a number line
- LeetCode 97 · MediumInterleaving StringBraiding two ribbons into one
- LeetCode 329 · HardLongest Increasing Path in a MatrixThe longest uphill hike on a terrain map
- LeetCode 115 · HardDistinct SubsequencesHow many ways to cross out letters and leave a word
- LeetCode 72 · MediumEdit DistanceFewest keystrokes to fix a typo
- LeetCode 312 · HardBurst BalloonsChoosing which balloon pops last
- LeetCode 10 · HardRegular Expression MatchingA stencil with wildcards and repeats
Greedy · 8
- LeetCode 53 · MediumMaximum Subarray (Kadane)The best winning streak in a trading diary
- LeetCode 55 · MediumJump GameA frog checking how far it could ever reach
- LeetCode 45 · MediumJump Game IIFewest hops, thinking one wave at a time
- LeetCode 134 · MediumGas StationA road trip around a ring of petrol stations
- LeetCode 846 · MediumHand of StraightsLaying a hand of cards out as runs
- LeetCode 1899 · MediumMerge Triplets to Form Target TripletMixing paint pots without overshooting a colour
- LeetCode 763 · MediumPartition LabelsCutting a ribbon so every letter stays in one piece
- LeetCode 678 · MediumValid Parenthesis StringBrackets with wildcard stars
Intervals · 6
- LeetCode 57 · MediumInsert IntervalSqueezing a new booking into a calendar
- LeetCode 56 · MediumMerge IntervalsMerging overlapping meetings into blocks
- LeetCode 435 · MediumNon-overlapping IntervalsCancelling the fewest bookings
- LeetCode 252 · EasyMeeting RoomsCan one person attend every meeting?
- LeetCode 253 · MediumMeeting Rooms IIHow many rooms does the office need?
- LeetCode 1851 · HardMinimum Interval to Include Each QueryThe shortest shift that covers each moment
Math & Geometry · 8
- LeetCode 48 · MediumRotate ImageTurning a photo a quarter turn, tile by tile
- LeetCode 54 · MediumSpiral MatrixA snail spiralling inward across a tiled garden
- LeetCode 73 · MediumSet Matrix ZeroesBroken lights knock out their whole row and column
- LeetCode 202 · EasyHappy NumberA chain of number plates that may loop
- LeetCode 66 · EasyPlus OneA car odometer rolling over
- LeetCode 50 · MediumPow(x, n)Folding paper to multiply fast
- LeetCode 43 · MediumMultiply StringsLong multiplication on squared paper
- LeetCode 2013 · MediumDetect SquaresPegs on a board that form squares
Bit Manipulation · 7
- LeetCode 136 · EasySingle NumberPairs of socks cancel; the odd one stays
- LeetCode 191 · EasyNumber of 1 BitsCounting the lights that are on
- LeetCode 338 · EasyCounting BitsEach number borrows its count from its half
- LeetCode 190 · EasyReverse BitsReading a switch panel in a mirror
- LeetCode 268 · EasyMissing NumberRoll call: who is missing?
- LeetCode 371 · MediumSum of Two IntegersAdding without +: sparks carry to the left
- LeetCode 7 · MediumReverse IntegerSpinning an odometer backwards, watching for overflow
More practice problems
Linked list
- LeetCode 24Swap Nodes in PairsSwapping coaches two at a time
- LeetCode 86Partition ListSorting coaches onto two sidings
- LeetCode 92Reverse Linked List IIReversing only part of a train
- LeetCode 142Linked List Cycle IIWhere does the loop begin?
- LeetCode 160Intersection of Two Linked ListsTwo branch lines joining one track
- LeetCode 203Remove Linked List ElementsUncoupling every coach with one number
- LeetCode 234Palindrome Linked ListFolding a train in half
- LeetCode 237Delete Node in a Linked ListRemoving a coach you’re standing in
- LeetCode 328Odd Even Linked ListOdd coaches first, then even
- LeetCode 445Add Two Numbers IIAdding from the back with two plate stacks
Two pointers
- LeetCode 26Remove Duplicates from Sorted ArrayA reader and a writer on a sorted shelf
- LeetCode 75Sort Colors (Dutch flag)Sorting red, white and blue marbles
- LeetCode 88Merge Sorted ArrayFilling a parking row from the back
- LeetCode 189Rotate ArrayTurning a carousel with three flips
- LeetCode 283Move ZeroesPushing empty slots to the end of a shelf
- LeetCode 344Reverse StringTwo friends swapping letter cards
Binary search
- LeetCode 34Find First and Last Position of Element in Sorted ArrayAll copies of one book on a sorted shelf
- LeetCode 35Search Insert PositionWhere does the new book go?
- LeetCode 162Find Peak ElementA hiker who always walks uphill
- LeetCode 540Single Element in a Sorted ArrayThe lone sock on a line of pairs
- LeetCode 1351Count Negative Numbers in a Sorted MatrixA staircase walk through freezing readings
- Classic剑指 Offer 53-IHow many copies of this book?
Stack
Queue · BFS
Hashing
- LeetCode 169Majority Element (Boyer–Moore)An election where opposite votes cancel
- LeetCode 219Contains Duplicate IIA coat check that only remembers recent guests
- LeetCode 290Word PatternMatching symbols to words, both ways
- LeetCode 349Intersection of Two ArraysWho is on both guest lists?
- LeetCode 350Intersection of Two Arrays IIMatching fruit from two baskets
- LeetCode 387First Unique Character in a StringThe first guest with a one-off ticket colour
- LeetCode 447Number of BoomerangsThrowers standing equally far apart
- LeetCode 4544Sum IIFour bags of numbered balls that cancel out
- LeetCode 771Jewels and StonesSorting jewels from a bag of stones
- LeetCode 1394Find Lucky Integer in an ArrayA raffle number that matches its count
Recursion · DP
Trees · DFS
Greedy
Bits · Math
- LeetCode 9Palindrome NumberFolding a number strip in half
- LeetCode 137Single Number IITriplets and one loner, counted switch by switch
- LeetCode 172Factorial Trailing ZeroesCounting pairs of shoes that make tens
- LeetCode 201Bitwise AND of Numbers RangeWhich switches stay on across a whole range?
- LeetCode 231Power of TwoA panel with exactly one switch on
- LeetCode 342Power of FourOne switch on, at an even position
- LeetCode 260Single Number IIITwo odd socks separated by one switch
- LeetCode 461Hamming DistanceHow many switches differ between two panels?
- LeetCode 477Total Hamming DistanceAll pairs of panels, one column at a time
- LeetCode 1281Subtract the Product and Sum of DigitsRolling the digits like dice