Given a grid of size N X M and a robot is placed at cell (N – 1, M – 1). Also, given string str which consists only of the characters ‘U’ (Up), ‘D’ (Down), ‘L’ (Left) and ‘R’ (Right) representing the moves the robot is going to perform within the grid. The task is to find whether the robot will be safe at the end of the last move. Robot is said to be safe if it is within the bounds of the grid.
Note: Consider that the rectangular grid is present below the number line with the top-left corner lying on the origin.
Input: N = 1, M = 1, str = “R”
As there is only 1 cell, no movement is allowed.
Input: N = 2, M = 3, str = “LLRU”
Approach: For every move, update the position of the robot inside the grid. if at any move the position of the robot is outside the grid then the output will be No else print Yes if for all the moves, the robot is within the bounds of the grid.
Below is the implementation of the above approach:
- Count possible moves in the given direction in a grid
- Check if it is possible to perform the given Grid Division
- Check if a grid can become row-wise and column-wise sorted after adjacent swaps
- Possible moves of knight
- Number of triangles after N moves
- Count number of 1s in the array after N moves
- Maximum prime moves to convert X to Y
- Minimum number of moves to reach N starting from (1, 1)
- Number of moves required to guess a permutation.
- Minimum number of given moves required to make N divisible by 25
- Minimum moves to reach target on a infinite line | Set 2
- Minimum number of moves after which there exists a 3X3 coloured square
- Total position where king can reach on a chessboard in exactly M moves | Set 2
- Find the index of the left pointer after possible moves in the array
- Total position where king can reach on a chessboard in exactly M moves
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.