Skip to content

Instantly share code, notes, and snippets.

@sai-sondarkar
Last active October 29, 2021 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sai-sondarkar/8e819ec8967f1ac98955bc0ea1309324 to your computer and use it in GitHub Desktop.
Save sai-sondarkar/8e819ec8967f1ac98955bc0ea1309324 to your computer and use it in GitHub Desktop.
Ankit is in maze. The command center sent him a string which decodes to come out from the maze.
He is initially at (0, 0).
String contains L, R, U, D denoting left, right, up and down.
In each command he will traverse 1 unit distance in the respective direction.
For example if he is at (2, 0) and the command is L he will go to (1, 0).
You guys just need to make the flow of the logic which updates the position after taking input from u L, R, U, D
@Omkaragrawal
Copy link

Sir please illustrate the question

@RevanthKumarM
Copy link

Please explain what needs to be done in the problem statement

@Abhinayah
Copy link

Sir, Please explain what to do in this problem.

@ks-1234
Copy link

ks-1234 commented Mar 25, 2020

Sir, please explain this question

@kavya506
Copy link

Sir,I can't understand this please explain

Copy link

ghost commented Mar 25, 2020

sir if i am not wrong then we can solve keeping mind the co-ordinate axes

@Akshay-2001
Copy link

but if we use co ordinate axis , we will end at the initial point

@tarun-logan
Copy link

Sir i didn't understand what has to be done here, could you please elaborate it? Thank you

@AbhijeetMankani
Copy link

Upwards is positive or negative, as in if U is received, then we increment the 2nd value or decrement it?

@Keerthana2704
Copy link

Keerthana2704 commented Jun 3, 2020 via email

@Thulasi422
Copy link

sir,can u explain the problem statement..plzz

@kritika-rai
Copy link

can't get the statement

@SumitK27
Copy link

As per what I understood from the problem statement, this should be the answer:

def getCoordinates(arr) :
    x = 0
    y = 0
    for i in arr  :
        if (i == 'L') :
            x = x-1
        elif (i == 'R') :
            x = x+1
        elif (i == 'U') :
            y = y+1
        elif (i == 'D') :
            y = y-1
    return [x,y]

print(getCoordinates(['L', 'U', 'U', 'D', 'U', 'U', 'R', 'D' ]))

Based on those inputs the output should be [0, 2]

Please tell me if that's an incorrect solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment