Practice Execution of All Suffix Instructions Staying in a Grid
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
A robot starts at startPos = [row, column] on an n by n grid whose coordinates range from 0 through n - 1. Instructions L, R, U, and D move it one cell left, right, up, or down. For each starting instruction index i in s, reset the robot to startPos and execute that suffix until the next move would leave the grid or no instructions remain. Return the count of valid executed instructions for every i, in order.
Source: Execution of All Suffix Instructions Staying in a Grid on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
n = 3, startPos = [0,1], s = "RRDDLU"
[1,5,4,3,1,0]
# Example 2
n = 2, startPos = [1,1], s = "LURD"
[4,1,0,0]
# Example 3
n = 1, startPos = [0,0], s = "LRUD"
[0,0,0,0]
Constraints
Related LeetCode Problems
Practice more problems similar to Execution of All Suffix Instructions Staying in a Grid.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.