- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# 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 i < n, update (increase i by 1), do: if grid[0, i] is same as '#' and grid[1, i] is same as '#', then: flag := 0 if flag is same as 0, then: print("Not Possible.") Otherwise print("Possible.")

## Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h> using namespace std; #define N 100 void solve(int n, string grid[]) { int flag = 1; for(int i = 0; i < n; i++){ if(grid[0].at(i) == '#' && grid[1].at(i) == '#'){ flag = 0; } } if (flag == 0) cout<<"Not Possible."; else cout<<"Possible."; } int main() { int n = 4; string grid[] = {".##.", "...."}; solve(n, grid); return 0; }

## Input

4, {".##.", "...."}

## Output

Possible.

- Related Questions & Answers
- C++ Program to find out if there is a pattern in a grid
- C++ code to find out if a name is male or female
- C++ code to find out if an image is B/W or color
- C++ code to find out if everyone will get ice cream
- How to find out if a Python object is a string?
- C++ code to find out number of battery combos
- How to find out if your teenager is addicted to drugs?
- Program to Find Out the Number of Squares in a Grid in Python
- C++ Program to find out the number of illuminated cells in a grid
- C++ Program to find out the number of border cells in a grid
- How to find out if an element is hidden with JavaScript?
- How to Find out the source code of a transaction in SAP?
- C++ code to find out which number can be greater
- C++ Program to find out if a round trip is possible from a particular city
- C++ Program to find out the number of sides that a polygon has inside a grid

Advertisements