I am trying Find the phone numbers of all managers whose direct report hierarchy live in more than 1 city in O(n) time complexity. Below is my approach which is using with Time Complexity O(M*N) where M is the number of managers and N is the Number of employess. Can someone please help me with O(N) solution for this problem.
Tag: depth-first-search
Find Number of steps needed to traverse from one top left to bottom right in a matrix
in Matrix A with 6 rows and 4 columns. where ‘#’ = blocked path and ‘.’ = allowed path.. How to find the number of steps needed to reach from top left to bottom left.I am able to traverse the matrix from top left to bottom right but unable to find the steps(which is 8 here)..But the code below I
Depth first search in finding a path in matrix
My understanding about dfs is using stack (bfs using queue). However, if i want to traversal a matrix in dfs. How do I suppose to do that? Suppose I have a matrix and I want to find a path start from top left to bottom right, and it can only move down and right. Above is an online version a
Knights tour – results in an infinite loop and i can’t figure out why
I’m trying to solve the knight’s tour problem using backtracking. I think the algorithm I have should work. I’ve tried but I can’t figure out why it isn’t working. It results in an infinite loop. However if I comment out the line that back track solutionBoard[dst.x][dst.y]=-1; it works! I just don’t understand why! Any help would be appreciated. Answer Your
Knight’s tour depth-first search infinite loop
I’m trying to solve the knight’s tour problem using a depth-first search algorithm. The algorithm seems te be looping whenever it has two choices that both result in a dead end. I understand that this is caused because the algorithm resets the ‘wasVisited’ boolean to false again whenever a dead end is found but i simply don’t know how to