@@ -0,0 +1,1911 @@
+# Time:  O(n + k)%0A# Space: O(k)%0A%0A# A robot on an infinite grid starts at point (0, 0) and faces north.%0A# The robot can receive one of three possible types of commands:%0A# - -2: turn left 90 degrees%0A# - -1: turn right 90 degrees%0A# - 1 %3C= x %3C= 9: move forward x units%0A#%0A# Some of the grid squares are obstacles. %0A#%0A# The i-th obstacle is at grid point (obstacles%5Bi%5D%5B0%5D, obstacles%5Bi%5D%5B1%5D)%0A#%0A# If the robot would try to move onto them,%0A# the robot stays on the previous grid square instead%0A# (but still continues following the rest of the route.)%0A#%0A# Return the square of the maximum Euclidean distance that%0A# the robot will be from the origin.%0A#%0A# Example 1:%0A#%0A# Input: commands = %5B4,-1,3%5D, obstacles = %5B%5D%0A# Output: 25%0A# Explanation: robot will go to (3, 4)%0A# Example 2:%0A#%0A# Input: commands = %5B4,-1,4,-2,4%5D, obstacles = %5B%5B2,4%5D%5D%0A# Output: 65%0A# Explanation: robot will be stuck at (1, 4) before turning left and going to (1, 8)%0A#%0A# Note:%0A# - 0 %3C= commands.length %3C= 10000%0A# - 0 %3C= obstacles.length %3C= 10000%0A# - -30000 %3C= obstacle%5Bi%5D%5B0%5D %3C= 30000%0A# - -30000 %3C= obstacle%5Bi%5D%5B1%5D %3C= 30000%0A# - The answer is guaranteed to be less than 2 %5E 31.%0A%0Aclass Solution(object):%0A    def robotSim(self, commands, obstacles):%0A        %22%22%22%0A        :type commands: List%5Bint%5D%0A        :type obstacles: List%5BList%5Bint%5D%5D%0A        :rtype: int%0A        %22%22%22%0A        directions = %5B(0, 1), (1, 0), (0, -1), (-1, 0)%5D%0A        x, y, i = 0, 0, 0%0A        lookup = set(map(tuple, obstacles))%0A        result = 0%0A        for cmd in commands:%0A            if cmd == -2:%0A                i = (i-1) %25 4%0A            elif cmd == -1:%0A                i = (i+1) %25 4%0A            else:%0A                for k in xrange(cmd):%0A                    if (x+directions%5Bi%5D%5B0%5D, y+directions%5Bi%5D%5B1%5D) not in lookup:%0A                        x += directions%5Bi%5D%5B0%5D%0A                        y += directions%5Bi%5D%5B1%5D%0A                        result = max(result, x*x + y*y)%0A        return result%0A

Create walking-robot-simulation.py