โ† All topics

๐ŸŒณ Interview Prep

Trees, Graphs & DP

Trees, heaps, tries, graphs, backtracking and dynamic programming: what separates a pass from a strong pass at big tech.

100 questions, most asked first

Ranked by how often each question comes up in real interviews. #1 is the most common.

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