Flipkart Interview Question for SDE-2s


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

Imagine you are in the Point Origin with (0,0). Clearly, movement can be only X,Y. Thus, the way to handle it is simply keeping track of the co-ordinates in a set, and check if I have visited the point before or not.
If I did, I am inside a loop.

One more thing. The question is incomplete. It also should give the direction the robot is facing right now, is it N,E,W, S ?

- NoOne April 27, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

l

- , April 29, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

,

- , April 29, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Nothing fancy, short and simple... I'm keeping track of the direction that the robot is facing. I mod on the direction which then dictates how to update our (x,y) coordinates.

def robot_moves(moves):
    direction = 0
    move_sets = [[0,0]]
    for move in moves:
        if move == "L":
            direction += 1
        elif move == "R":
            direction -= 1
        elif move == "G":
            set_ = move_sets[-1].copy()
            print(set_)
            if direction % 4 == 0:
                set_[0] += 1
            elif direction % 4 == 1:
                set_[1] -= 1
            elif direction % 4 == 2:
                set_[0] -= 1
            elif direction % 4 == 3:
                set_[1] += 1
            if set_ in move_sets:
                return True
            move_sets.append(set_)
    return False

- AutobotAuz May 07, 2019 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More