Stokastik

Machine Learning, AI and Programming

Tag: Depth First Search

Leetcode : Bricks Falling When Hit

Problem Statement Solution: This is a trick problem. I will come later to explain why. So the most logical approach to solve the problem is to first 'hit & erase' one of the brick A and then for each of the adjacent bricks of A, check if they are 'connected' to the top of the grid. If they are connected to the top of the grid don't do anything, else […]

Continue Reading →

LeetCode : Swim in Rising Water

Problem Statement Solution : One possible solution is to see whether for each water level, he can swim from (0, 0) to (N-1, N-1) without waiting anywhere in between. To check whether he can swim fromĀ (0, 0) to (N-1, N-1) i.e. there exists a path, we can use DFS or BFS to traverse the matrix. He can swim from point A to B if the height of B is less […]

Continue Reading →