We are given a two-dimensional board of size N x M (N rows and M columns). Each field of the board can be empty (.), may contain an obstacle (X') or may have a character in it. The character might be either an assassin ('A') or a guard. Each guard stands still and looks straight ahead, in the direction they are facing. Every guard looks in one of four directions (up, down, left or right on the board) and is represented by one of four symbols. A guard denoted by '<' is looking to the left; by ">, to the right; "^, up; or 'V', down. The guards can see everything in a straight line in the direction in which they are facing, as far as the first obstacle (X' or any other guard) or the edge of the board. The assassin can move from the current field to any other empty field with a shared edge. The assassin cannot move onto fields containing obstacles or enemies. Write a function: class Solution { public boolean solution(String[] B); } that, given an array B consisting of N strings denoting rows of the array, returns true if is it possible for the assassin to sneak from their current location to the bottom-right cell of the board undetected, and false otherwise. Examples: 1. Given B = [X.....>, '. observed by a guard. X A v X A ."], your function should return false. All available paths lead through a field 2. Given B = [...Xv", "AX. .^", ".XX.."], your function should return true. The guard in the second row is blocking the other one from watching the bottom-right square. ***** AX X X 3. Given B = [...",">.A"], your function should return false, as the assassin gets spotted right at the start. v 4. Given B =[A.v",...], your function should return false. It's not possible for the assassin to enter the bottom-right cell undetected, as the cell is observed. Write an efficient algorithm for the following assumptions: • N is an integer within the range [1..500]; all strings in B are of the same length M from range [1..500]; • there is exactly one assassin on the board; there is no guard or wall on B[N-1][M-1]; • every string in B consists only of the following characters and/or 'A'.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

UH: Question 2: 

 

We are given a two-dimensional board of size N X M (N rows and M columns). Each field of the board can be empty (-), may contain an
obstacle ('X') or may have a character in it. The character might be either an assassin ('A') or a guard. Each guard stands still and looks
straight ahead, in the direction they are facing.
Every guard looks in one of four directions (up, down, left or right on the board) and is represented by one of four symbols. A guard
denoted by '<' is looking to the left; by '>', to the right; "", up; or 'v', down. The guards can see everything in a straight line in the direction in
which they are facing, as far as the first obstacle (X' or any other guard) or the edge of the board.
The assassin can move from the current field to any other empty field with a shared edge. The assassin cannot move onto fields
containing obstacles or enemies.
Write a function:
class Solution { public boolean solution(String[] B); }
that, given an array B consisting of N strings denoting rows of the array, returns true if is it possible for the assassin to sneak from their
current location to the bottom-right cell of the board undetected, and false otherwise.
Examples:
1. Given B = [X.....>','
observed by a guard.
X
A
A
v
X
2. Given B = [...Xv", "AX..",".XX..], your function should return true. The guard in the second row is blocking the other one from
watching the bottom-right square.
A
X X
X
x
>
."], your function should return false. All available paths lead through a field
3. Given B = [...",">. A"], your function should return false, as the assassin gets spotted right at the start.
4. Given B = ['A.v", ..."], your function should return false. It's not possible for the assassin to enter the bottom-right cell undetected, as
the cell is observed.
Write an efficient algorithm for the following assumptions:
• N is an integer within the range [1..500];
• all strings in B are of the same length M from range [1..500];
• there is exactly one assassin on the board;
• there is no guard or wall on B[N-1][M-1];
• every string in B consists only of the following characters !!, 'X,
and/or 'A'.
Transcribed Image Text:We are given a two-dimensional board of size N X M (N rows and M columns). Each field of the board can be empty (-), may contain an obstacle ('X') or may have a character in it. The character might be either an assassin ('A') or a guard. Each guard stands still and looks straight ahead, in the direction they are facing. Every guard looks in one of four directions (up, down, left or right on the board) and is represented by one of four symbols. A guard denoted by '<' is looking to the left; by '>', to the right; "", up; or 'v', down. The guards can see everything in a straight line in the direction in which they are facing, as far as the first obstacle (X' or any other guard) or the edge of the board. The assassin can move from the current field to any other empty field with a shared edge. The assassin cannot move onto fields containing obstacles or enemies. Write a function: class Solution { public boolean solution(String[] B); } that, given an array B consisting of N strings denoting rows of the array, returns true if is it possible for the assassin to sneak from their current location to the bottom-right cell of the board undetected, and false otherwise. Examples: 1. Given B = [X.....>',' observed by a guard. X A A v X 2. Given B = [...Xv", "AX..",".XX..], your function should return true. The guard in the second row is blocking the other one from watching the bottom-right square. A X X X x > ."], your function should return false. All available paths lead through a field 3. Given B = [...",">. A"], your function should return false, as the assassin gets spotted right at the start. 4. Given B = ['A.v", ..."], your function should return false. It's not possible for the assassin to enter the bottom-right cell undetected, as the cell is observed. Write an efficient algorithm for the following assumptions: • N is an integer within the range [1..500]; • all strings in B are of the same length M from range [1..500]; • there is exactly one assassin on the board; • there is no guard or wall on B[N-1][M-1]; • every string in B consists only of the following characters !!, 'X, and/or 'A'.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Topological Sort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education