## Flipkart Interview Question for SDE-2s

• 1
of 1 vote

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 ?

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

l

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

,

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``````

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.

### 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.