-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathwalking-robot-simulation.md
47 lines (34 loc) · 1.82 KB
/
walking-robot-simulation.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<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>
<ul>
<li><code>-2</code>: turn left 90 degrees</li>
<li><code>-1</code>: turn right 90 degrees</li>
<li><code>1 <= x <= 9</code>: move forward <code>x</code> units</li>
</ul>
<p>Some of the grid squares are obstacles. </p>
<p>The <code>i</code>-th obstacle is at grid point <code>(obstacles[i][0], obstacles[i][1])</code></p>
<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>
<p>Return the <strong>square</strong> of the maximum Euclidean distance that the robot will be from the origin.</p>
<p> </p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong>commands = <span id="example-input-1-1">[4,-1,3]</span>, obstacles = <span id="example-input-1-2">[]</span>
<strong>Output: </strong><span id="example-output-1">25</span>
<span>Explanation: </span>robot will go to (3, 4)
</pre>
<div>
<p><strong>Example 2:</strong></p>
<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>
<strong>Output: </strong><span id="example-output-2">65</span>
<strong>Explanation</strong>: robot will be stuck at (1, 4) before turning left and going to (1, 8)
</pre>
</div>
<p> </p>
<p><strong>Note:</strong></p>
<ol>
<li><code>0 <= commands.length <= 10000</code></li>
<li><code>0 <= obstacles.length <= 10000</code></li>
<li><code>-30000 <= obstacle[i][0] <= 30000</code></li>
<li><code>-30000 <= obstacle[i][1] <= 30000</code></li>
<li>The answer is guaranteed to be less than <code>2 ^ 31</code>.</li>
</ol>