🌳 Trees & Graphs Problems

Master binary trees, BST, graph traversal, topological sort, and tree/graph algorithms

Binary Tree Level Order Traversal - BFS

Medium

Return the level order traversal of a binary tree (values by level from left to right).

java

Validate Binary Search Tree

Medium

Determine if a binary tree is a valid BST.

java

Lowest Common Ancestor of Binary Tree

Medium

Find the lowest common ancestor (LCA) of two nodes in a binary tree.

java

Number of Islands - DFS/BFS Grid Traversal

Medium

Count the number of islands in a 2D grid (1 = land, 0 = water).

java

Course Schedule - Detect Cycle in Directed Graph

Medium

Determine if you can finish all courses given prerequisites (detect cycle in DAG).

java

Clone Graph - Deep Copy Graph with Cycles

Medium

Return a deep copy of a connected undirected graph.

java

Binary Tree Maximum Path Sum

Hard

Find the maximum path sum in a binary tree. Path can start and end at any node.

java

Serialize and Deserialize Binary Tree

Hard

Design an algorithm to serialize and deserialize a binary tree.

java

Trees & Graphs Patterns