Question: how to test We are given a two - dimensional board of size N M ( N rows and M columns ) . Each field
how to test We are given a twodimensional board of size NM 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 e is looking to the left; by to the right; c 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 solutionString 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 bottomright cell of the board undetected, and false otherwise. Examples: Given BXvXXA your function should return false. All available paths lead through a field observed by a guard. Given BXvAX A XX your function should return true. The guard in the second row is blocking the other one from watching the bottomright square. Given BA your function should return false, as the assassin gets spotted right at the start. Given B Av your function should return false. It's not possible for the assassin to enter the bottomright cell undetected, as the cell is observed. Write an efficient algorithm for the following assumptions: N is an integer within the range ; all strings in B are of the same length M from range ; there is exactly one assassin on the board; there is no guard or wall on BNM; every string in B consists only of the following characters Xvn andor A
Guards can appear the following way in the matrix: represents a guard that is looking to the left, represents a guard that is looking to the right, looks up and v is looking down. Their line of sight extends as long as there is an obstacle, edge of the matrix or another guard.
Write a function that calculates whether the assassin can reach the bottomright corner of the matrix. The assassin can not step in the line of sight of any guard.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
