Wesam and Omar
Practice
4 (2 votes)
Basics of greedy algorithms
Algorithms
Greedy algorithms
Problem
69% Success 604 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a grid of size 3*3 that has the following specifications:

  • Each cell in the grid is either empty '.' or occupied '*'.
  • you can't move to an occupied cell.
  • Wesam starts at cell (1,1) and wants to reach Omar who is in cell (3,3).
  • Wesam can move vertically, horizontally, and diagonally.

Note:If Wesam is standing at cell (x,y), he can go to :(x+1,y) , (x-1,y), (x,y+1) , (x,y-1), (x+1,y+1) , (x-1,y-1).

Note: rows are numbered from top to down, and columns are numbered from left to right.

Write a program to find if Wesam can reach Omar or not.

Input format:

  • First line: T (number of test cases)
    For each test case
  • 3 lines: 3 characters (denoting each cell in the grid.

It's guaranteed that cell (1,1) and cell (3,3) are empty.

Output format:

For each test case print "YES" (without quotes) if Wesam can reach Omar. Print "NO" (without quotes) otherwise.

Constraints

1<= T <= 100

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
10 votes
Tags:
Greedy AlgorithmsBasics of Greedy AlgorithmsAlgorithms
Points:10
6 votes
Tags:
AlgorithmsGreedy Algorithms
Points:10
8 votes
Tags:
Greedy AlgorithmsAlgorithmsBasics of Greedy AlgorithmsGreedy algorithm