Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C++ code to find out if a grid is fully accessible
Suppose, we are given a grid that has 2 rows and n columns. A robot is at position (0, 0) in the grid and wants to visit (1, n - 1) by visiting adjacent and corner cells to its current location. We are given the grid in an array of strings, a cell is blocked if it is marked '#' and it is accessible if it is marked '.'. We have to find out if the robot can visit cell (1, n - 1) from the cell (0, 0).
So, if the input is like n = 4, grid = {".##.", "...."}, then the output will be Possible.
Steps
To solve this, we will follow these steps −
flag := 1 for initialize i := 0, when iExample
Let us see the following implementation to get better understanding −
#includeusing namespace std; #define N 100 void solve(int n, string grid[]) { int flag = 1; for(int i = 0; i Input
4, {".##.", "...."}Output
Possible.
Advertisements
