<p>There is an <code>n x n</code> grid, with the top-left cell at <code>(0, 0)</code> and the bottom-right cell at <code>(n - 1, n - 1)</code>. You are given the integer <code>n</code> and an integer array <code>startPos</code> where <code>startPos = [start<sub>row</sub>, start<sub>col</sub>]</code> indicates that a robot is initially at cell <code>(start<sub>row</sub>, start<sub>col</sub>)</code>.</p>
<p>You are also given a <strong>0-indexed</strong> string <code>s</code> of length <code>m</code> where <code>s[i]</code> is the <code>i<sup>th</sup></code> instruction for the robot: <code>'L'</code> (move left), <code>'R'</code> (move right), <code>'U'</code> (move up), and <code>'D'</code> (move down).</p>
<p>The robot can begin executing from any <code>i<sup>th</sup></code> instruction in <code>s</code>. It executes the instructions one by one towards the end of <code>s</code> but it stops if either of these conditions is met:</p>
<ul>
<li>The next instruction will move the robot off the grid.</li>
<li>There are no more instructions left to execute.</li>
</ul>
<p>Return <em>an array</em><code>answer</code><em>of length</em><code>m</code><em>where</em><code>answer[i]</code><em>is <strong>the number of instructions</strong> the robot can execute if the robot <strong>begins executing from</strong> the</em><code>i<sup>th</sup></code><em>instruction in</em><code>s</code>.</p>