Dfs

Alien Dictionary

Given a sorted dictionary of alien language, find the order of characters in the alien alphabet

All Paths From Source to Target

Find all possible paths from source node to target node in a directed acyclic graph (DAG)

Articulation Points (Cut Vertices)

Find all articulation points in an undirected graph - vertices whose removal increases the number of connected components

Binary Tree Inorder Traversal

Traverse a binary tree in inorder (left -> root -> right)

Binary Tree Preorder Traversal

Traverse a binary tree in preorder (root -> left -> right)

Boundary Traversal of Binary Tree

Traverse the boundary of a binary tree in anti-clockwise direction.

Clone Graph

Create a deep copy of an undirected graph represented with adjacency lists

Count Good Nodes in Binary Tree

Count the number of nodes in a binary tree where the path from root to that node has no nodes with values greater than the current node.

Course Schedule

Determine if you can finish all courses given prerequisite relationships using topological sorting

Depth-First Search (DFS)

Implement depth-first search traversal for graphs

Detect Cycle in Directed Graph

Determine if a directed graph contains a cycle

Detect Cycle in Undirected Graph

Determine if an undirected graph contains a cycle

Diameter of Binary Tree

Find the diameter (longest path) of a binary tree.

Find Bridges in a Graph

Find all bridges (critical edges) in an undirected graph using Tarjan's algorithm

Invert Binary Tree

Invert (mirror) a binary tree by swapping left and right children

Is Graph Bipartite

Check if a graph can be colored with exactly two colors such that no two adjacent nodes have the same color

Lowest Common Ancestor

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

Maximum Depth of Binary Tree

Find the maximum depth (height) of a binary tree

Maximum Path Sum

Find the maximum path sum in a binary tree.

Number of Islands

Count the number of islands in a 2D grid

Path Sum

Check if there exists a root-to-leaf path with given sum.

Postorder Traversal

Traverse binary tree in postorder (left, right, root)

Print All Root-to-Leaf Paths

Print all root-to-leaf paths in a binary tree

Serialize and Deserialize Binary Tree

Serialize a binary tree to a string and deserialize it back to the original tree

Strongly Connected Components

Find all strongly connected components in a directed graph

Symmetric Tree

Check if a binary tree is symmetric around its center.

Topological Sort

Find a linear ordering of vertices in a directed acyclic graph

Vertical Order Traversal of Binary Tree

Traverse a binary tree vertically and return nodes by columns