accountforcheating's blog

By accountforcheating, history, 4 years ago, In English

A robot stands at (0,0), with its back against an infinite wall defined by y = 0. It can receive one of three instructions: 1. “G”: go straight 1 unit 2. “L”: turn 90 degrees to the left 3. “R”: turn 90 degrees to the right

The robot performs the instructions given in order, and repeats them till it encounters the wall again. Return true if and only if a final position exists.

Note: 1. 1 <= instructions.length <= 100 2. instructions[i] is in {‘G’, ‘L’, ‘R’}

Output Format: "0" for false (without "") "1" for true (without "") Sample Input: GLR Sample Output: 0

»
4 years ago, # |
  Vote: I like it +13 Vote: I do not like it

My bet ? If you didn't know already , accountforcheating doesn't make you seem trustworthy :(

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

did mean us to solve it for you?, its quite ez, just perform the actions 4 times, if u encountered the wall, then its done, print "1", if u didn't, then you wont encounter the wall, never. as after performing the actions 4 times, you are now heading to positive side of x-axis(its true for every input) lets say you are in position <x, y> after doing the whole actions 4 times. for sure &x& is bigger than or equal to zero(if it's not, then you encountered the wall before that, so you wont reach here), and no matter what &y& is equal to. now you are further from the wall and you wont touch it for ever. it could have been a div.2 B problem. if you would not spoil it here.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    did you mean*, and the time complexity is O(n) (it performs 4*n actions), so its good