thecodingcompany
DSA Pattern

Trees & Graphs

Traversal, recursion and the graph problems that separate candidates.

Problems5
FocusPattern + approach

5 problems

Attempt each problem before reading the approach. In the interview, state the pattern and complexity out loud first — that is what earns the marks.

01Maximum Depth of a Binary TreeEasyRecursion
ProblemReturn the number of nodes along the longest path from root to leaf.
Approach. Recurse: depth = 1 + max(depth(left), depth(right)). O(n) time.
02Validate a Binary Search TreeMediumBST
ProblemCheck whether a binary tree satisfies the BST property.
Approach. Recurse with (low, high) bounds rather than comparing only to the direct parent.
03Number of IslandsMediumGraph Traversal
ProblemCount connected groups of land cells in a grid.
Approach. Scan the grid; on each unvisited land cell, flood-fill with DFS or BFS and increment the count.
04Level Order TraversalMediumBFS
ProblemReturn the values of a binary tree grouped level by level.
Approach. BFS with a queue, processing exactly the current queue length per level.
05Course Schedule (Cycle Detection)MediumTopological Sort
ProblemGiven prerequisite pairs, determine whether all courses can be completed.
Approach. Build a directed graph and run topological sort; if any node remains, there is a cycle.

Practise here. Get placed there.

Prep+ is unlimited practice. When you are ready to turn it into an offer, TCC Placement Partner handles portfolio, resume and interviews.