# Tag Archives: DFS

Given an array arr[] of size N and an integer k. Return True, otherwise False, if there’s any way to reach the last element of… Read More
Given a tree with N vertices from 0 to N-1 (0th node is root) and val[] where val[i] denotes the value of the ith vertex.… Read More
Given a grid of dimension M * N where each cell varies from 1 to 6 and each of the values present in the cell… Read More
Given a tree consisting of N nodes where the value of each node is the negative of its node number (i.e., 1st node has a… Read More
Given a grid of size N * M consisting of O’s and X’s. The task is to find the number of ‘X’ total shapes. Note:… Read More
Given a set of 109 nodes. There are N bidirectional connections, and ith connection connects the Aith​ and Bith​ nodes. Starting from the first node,… Read More
Given an N x N binary matrix grid, where 0 represents a sea cell and 1 represents a land cell. A move consists of walking… Read More
Given a tree with N nodes, an array A[] of size N denoting the value of each node and array edges [][] of size (N-1),… Read More
To understand this let’s take a binary tree Binary tree If we conduct BFS in this tree: In level 0 there is one node in… Read More
Given a character matrix consisting of O’s and X’s, find the number of submatrices containing only ‘X’ and surrounded by ‘O’ from all sides.  Examples:… Read More
Given a 2-D array A[][] of size N×3, where each element of the array consists of {x, y, r}, where x and y are coordinates… Read More
Generally, when we come across a graph problem, we might need to traverse the structure of the given graph or tree to find our solution… Read More
Given N tanks connected like a tree, the connections between them in an array Edge[][], and the capacity of each tank in the array cap[],… Read More
Given a directed graph with N nodes and M edges in array V[], the task is to find the number of nodes that are accessible… Read More
Given an undirected tree with N nodes numbered from 1 to N and an array A[] where A[i] denotes the value assigned to (i+1)th node.… Read More