Skip to content

Interview Questions

Practice these in order. Start with Easy to build confidence, then move to Medium and Hard.


#Problem NameKey Idea
1Maximum Depth of Binary TreeDFS height calculation
2Invert Binary TreeSwap left and right at each node
3Symmetric TreeCompare left and right subtrees mirror-wise
4Path SumReduce target as you recurse down
5Same TreeCompare node values recursively
6Merge Two Binary TreesAdd values at overlapping nodes
7Search in a BSTUse BST property to guide direction
8Range Sum of BSTDFS, only traverse within valid range

#Problem NameKey Idea
1Binary Tree Level Order TraversalBFS with level-size tracking
2Validate Binary Search TreePass min/max bounds down
3Construct BST from PreorderRecursively split using BST property
4Kth Smallest Element in BSTInorder traversal (gives sorted order)
5Binary Tree Right Side ViewBFS, take last node of each level
6Diameter of Binary TreeTrack left height + right height at each node
7Lowest Common Ancestor (Binary Tree)Return node if found; merge at split point
8Count Good Nodes in Binary TreePass max value seen so far down
9Path Sum II (all paths)Backtracking: add to path, recurse, then pop
10Flatten Binary Tree to Linked ListPreorder traversal; wire right pointers
11Populating Next Right PointersBFS level-order
12Convert Sorted Array to BSTPick middle as root, recurse on halves

#Problem NameKey Idea
1Binary Tree Maximum Path SumGlobal max; return max single-branch gain upward
2Serialize and Deserialize Binary TreePreorder with null markers
3Binary Tree CamerasGreedy postorder; place camera at parent of uncovered leaf
4Recover Binary Search TreeFind two swapped nodes via inorder; swap their values
5Count of Smaller Numbers After SelfBST/Fenwick tree; insert right-to-left
6Vertical Order TraversalBFS + sort by (col, row, val)

StepWhat to do
1Solve Easy problems until you can code them without looking
2Learn the patterns — they’re the building blocks for Medium problems
3Master DFS and BFS completely
4For each Medium problem, identify which pattern it uses
5Draw the tree on paper and trace your algorithm before coding
6Test with null, single node, and edge cases
7Attempt Hard problems only after comfortably solving Medium ones