There is an N x M rectangular island that borders both the Pacific Ocean and the Atlantic Ocean. The Pacific Ocean touches the island’s left… Read More

# Tag Archives: DFS

Given a tree with N nodes and (N-1) edges and source node is at 1st position. There are Q queries, each of the type {pos,… Read More

Given a 2D grid arr[][] of ‘W’ and ‘L’ where ‘W’ denotes water and ‘L’ denotes land, the task is to find the minimum number… Read More

Given a graph with N vertices numbered from 0 to (N-1) and a matrix edges[][] representing the edges of the graph, the task is to… Read More

Given a binary tree, find the total time to visit all nodes from the root node. Visiting a child node from its parent node will… Read More

Given a undirected graph with V vertices and E edges. The task is to perform DFS traversal of the graph. Examples: Input: V = 7,… Read More

Given a binary tree and a number K, the task is to count the number of nodes having the average of the values in their… Read More

Question: Given an arbitrary binary tree, convert it to a binary tree that holds Children Sum Property. You can only increment data values in any… Read More

Given two integers N and M denoting the number of vertices and edges in the graph and array edges[][] of size M, denoting an edge… Read More

Given a graph root, the task is to find the length of the longest increasing sequence in the graph. Example: Input: root = 7—-17 … Read More

Given a graph root, and a value K, the task is to find the number of nodes in the graph whose sum of neighbors is… Read More

We have discussed flattening of a multi-level linked list where nodes have two pointers down and next. In the previous post, we flattened the linked… Read More