|
| 1 | +<h2>unknown-problem</h2><h3>Easy</h3><hr><div><p>A robot on an infinite grid starts at point (0, 0) and faces north. The robot can receive one of three possible types of commands:</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li><code>-2</code>: turn left 90 degrees</li> |
| 5 | + <li><code>-1</code>: turn right 90 degrees</li> |
| 6 | + <li><code>1 <= x <= 9</code>: move forward <code>x</code> units</li> |
| 7 | +</ul> |
| 8 | + |
| 9 | +<p>Some of the grid squares are obstacles. </p> |
| 10 | + |
| 11 | +<p>The <code>i</code>-th obstacle is at grid point <code>(obstacles[i][0], obstacles[i][1])</code></p> |
| 12 | + |
| 13 | +<p>If the robot would try to move onto them, the robot stays on the previous grid square instead (but still continues following the rest of the route.)</p> |
| 14 | + |
| 15 | +<p>Return the <strong>square</strong> of the maximum Euclidean distance that the robot will be from the origin.</p> |
| 16 | + |
| 17 | +<p> </p> |
| 18 | + |
| 19 | +<p><strong>Example 1:</strong></p> |
| 20 | + |
| 21 | +<pre><strong>Input: </strong>commands = <span id="example-input-1-1">[4,-1,3]</span>, obstacles = <span id="example-input-1-2">[]</span> |
| 22 | +<strong>Output: </strong><span id="example-output-1">25</span> |
| 23 | +<span>Explanation: </span>robot will go to (3, 4) |
| 24 | +</pre> |
| 25 | + |
| 26 | +<div> |
| 27 | +<p><strong>Example 2:</strong></p> |
| 28 | + |
| 29 | +<pre><strong>Input: </strong>commands = <span id="example-input-2-1">[4,-1,4,-2,4]</span>, obstacles = <span id="example-input-2-2">[[2,4]]</span> |
| 30 | +<strong>Output: </strong><span id="example-output-2">65</span> |
| 31 | +<strong>Explanation</strong>: robot will be stuck at (1, 4) before turning left and going to (1, 8) |
| 32 | +</pre> |
| 33 | +</div> |
| 34 | + |
| 35 | +<p> </p> |
| 36 | + |
| 37 | +<p><strong>Note:</strong></p> |
| 38 | + |
| 39 | +<ol> |
| 40 | + <li><code>0 <= commands.length <= 10000</code></li> |
| 41 | + <li><code>0 <= obstacles.length <= 10000</code></li> |
| 42 | + <li><code>-30000 <= obstacle[i][0] <= 30000</code></li> |
| 43 | + <li><code>-30000 <= obstacle[i][1] <= 30000</code></li> |
| 44 | + <li>The answer is guaranteed to be less than <code>2 ^ 31</code>.</li> |
| 45 | +</ol> |
| 46 | +</div> |
0 commit comments