π³ Interview Prep
Trees, Graphs & DP
Trees, heaps, tries, graphs, backtracking and dynamic programming: what separates a pass from a strong pass at big tech.
π Learn it from scratch
Visual, hands-on lessons for every pattern in this topic. Do the lesson, then come back and the questions click.
100 questions, most asked first
Ordered so the most useful questions for learning each pattern come first.
All patternsTree DFSTree BFSBSTGrid graph1D DPHeapGraph BFS/DFSTopological sortBacktracking2D DPTrieUnion-findShortest pathRecursion
#1β¨οΈMaximum Depth of Binary TreeTree DFSEasyFree#2β¨οΈInvert Binary TreeTree DFSEasyFree#3β¨οΈSame TreeTree DFSEasyFree#4β¨οΈBinary Tree Level Order TraversalTree BFSMediumFree#5β¨οΈValidate Binary Search TreeBSTMediumFree#6β¨οΈLowest Common Ancestor of a BSTBSTMediumFree#7β¨οΈNumber of IslandsGrid graphMediumFree#8β¨οΈClimbing Stairs1D DPEasyFree#9β¨οΈCoin Change1D DPMediumFree#10β¨οΈKth Largest Element in an ArrayHeapMediumFreeπUnlock 90 more Trees, Graphs & DP questions Β· all 1,200 questions for $39/year (about 11Β’ a day)See full access#11β¨οΈSubtree of Another TreeTree DFSEasyπ#12β¨οΈDiameter of Binary TreeTree DFSEasyπ#13β¨οΈBalanced Binary TreeTree DFSEasyπ#14β¨οΈBinary Tree Right Side ViewTree BFSMediumπ#15β¨οΈKth Smallest Element in a BSTBSTMediumπ#16β¨οΈConstruct Binary Tree from Preorder and InorderTree DFSMediumπ#17β¨οΈSerialize and Deserialize Binary TreeTree BFSHardπ#18β¨οΈBinary Tree Maximum Path SumTree DFSHardπ#19β¨οΈLowest Common Ancestor of a Binary TreeTree DFSMediumπ#20β¨οΈClone GraphGraph BFS/DFSMediumπ#21β¨οΈCourse ScheduleTopological sortMediumπ#22β¨οΈCourse Schedule IITopological sortMediumπ#23β¨οΈPacific Atlantic Water FlowGrid graphMediumπ#24β¨οΈRotting OrangesGrid graphMediumπ#25β¨οΈMax Area of IslandGrid graphMediumπ#26β¨οΈWord SearchBacktrackingMediumπ#27β¨οΈSubsetsBacktrackingMediumπ#28β¨οΈPermutationsBacktrackingMediumπ#29β¨οΈCombination SumBacktrackingMediumπ#30β¨οΈGenerate ParenthesesBacktrackingMediumπ#31β¨οΈHouse Robber1D DPMediumπ#32β¨οΈHouse Robber II1D DPMediumπ#33β¨οΈLongest Increasing Subsequence1D DPMediumπ#34β¨οΈWord Break1D DPMediumπ#35β¨οΈDecode Ways1D DPMediumπ#36β¨οΈUnique Paths2D DPMediumπ#37β¨οΈLongest Common Subsequence2D DPMediumπ#38β¨οΈEdit Distance2D DPMediumπ#39β¨οΈLongest Palindromic Substring2D DPMediumπ#40β¨οΈPalindromic Substrings2D DPMediumπ#41β¨οΈImplement Trie (Prefix Tree)TrieMediumπ#42β¨οΈDesign Add and Search WordsTrieMediumπ#43β¨οΈWord Search IITrieHardπ#44β¨οΈFind Median from Data StreamHeapHardπ#45β¨οΈK Closest Points to OriginHeapMediumπ#46β¨οΈLast Stone WeightHeapEasyπ#47β¨οΈTask SchedulerHeapMediumπ#48β¨οΈNumber of Connected Components in a GraphUnion-findMediumπ#49β¨οΈGraph Valid TreeUnion-findMediumπ#50β¨οΈRedundant ConnectionUnion-findMediumπ#51β¨οΈNetwork Delay TimeShortest pathMediumπ#52β¨οΈCheapest Flights Within K StopsShortest pathMediumπ#53β¨οΈWord LadderGraph BFS/DFSHardπ#54β¨οΈAlien DictionaryTopological sortHardπ#55β¨οΈSurrounded RegionsGrid graphMediumπ#56β¨οΈShortest Path in Binary MatrixGrid graphMediumπ#57β¨οΈN-QueensBacktrackingHardπ#58β¨οΈLetter Combinations of a Phone NumberBacktrackingMediumπ#59β¨οΈCombination Sum IIBacktrackingMediumπ#60β¨οΈSubsets IIBacktrackingMediumπ#61β¨οΈPalindrome PartitioningBacktrackingMediumπ#62β¨οΈMin Cost Climbing Stairs1D DPEasyπ#63β¨οΈMaximum Product Subarray1D DPMediumπ#64β¨οΈPartition Equal Subset Sum1D DPMediumπ#65β¨οΈCoin Change II1D DPMediumπ#66β¨οΈTarget Sum1D DPMediumπ#67β¨οΈMinimum Path Sum2D DPMediumπ#68β¨οΈLongest Increasing Path in a Matrix2D DPHardπ#69β¨οΈInterleaving String2D DPMediumπ#70β¨οΈBest Time to Buy and Sell Stock with Cooldown2D DPMediumπ#71β¨οΈMaximal Square2D DPMediumπ#72β¨οΈBinary Tree Inorder Traversal (Iterative)Tree DFSEasyπ#73β¨οΈSymmetric TreeTree DFSEasyπ#74β¨οΈPath SumTree DFSEasyπ#75β¨οΈPath Sum IIBacktrackingMediumπ#76β¨οΈCount Good Nodes in Binary TreeTree DFSMediumπ#77β¨οΈConvert Sorted Array to Balanced BSTBSTEasyπ#78β¨οΈDelete Node in a BSTBSTMediumπ#79β¨οΈInsert into a BSTBSTMediumπ#80β¨οΈBinary Tree Zigzag Level Order TraversalTree BFSMediumπ#81β¨οΈAverage of Levels in Binary TreeTree BFSEasyπ#82β¨οΈMinimum Depth of Binary TreeTree BFSEasyπ#83β¨οΈFlatten Binary Tree to Linked ListTree DFSMediumπ#84β¨οΈSum Root to Leaf NumbersTree DFSMediumπ#85β¨οΈAll Nodes Distance K in Binary TreeGraph BFS/DFSMediumπ#86β¨οΈIs Graph Bipartite?Graph BFS/DFSMediumπ#87β¨οΈKeys and RoomsGraph BFS/DFSMediumπ#88β¨οΈFind the Town JudgeGraph BFS/DFSEasyπ#89β¨οΈEvaluate DivisionGraph BFS/DFSMediumπ#90β¨οΈAccounts MergeUnion-findMediumπ#91β¨οΈJump Game II1D DPMediumπ#92β¨οΈMin Cost to Connect All PointsUnion-findMediumπ#93β¨οΈSwim in Rising WaterShortest pathHardπ#94β¨οΈPath With Minimum EffortShortest pathMediumπ#95β¨οΈFibonacci Number (Recursion β Memo β DP)RecursionEasyπ#96β¨οΈLetter Case PermutationBacktrackingMediumπ#97β¨οΈBurst Balloons2D DPHardπ#98β¨οΈRegular Expression Matching2D DPHardπ#99β¨οΈReconstruct ItineraryGraph BFS/DFSHardπ#100β¨οΈUnique Binary Search Trees1D DPMediumπ