## Interview Question for Software Engineers

Country: United States

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

Is the second element in the output supposed to be ">V<^"?

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

``````def loop_finder(direction_list):
direction_dict = {}
direction_dict['^'] = [0, 1]
direction_dict['V'] = [0, -1]
direction_dict['>'] = [1, 0]
direction_dict['<'] = [-1, 0]

position = [0, 0]
past_positions = []
past_positions.append(position[:])
loops = []
for n, d in enumerate(direction_list):
position[0] += direction_dict[d][0]
position[1] += direction_dict[d][1]
if position in past_positions:
idx = past_positions.index(position)
loops.append(direction_list[idx:n+1])
past_positions[idx] = ['X', 'X']
past_positions.append(position[:])
return loops``````

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

``````def loop_finder(direction_list):
direction_dict = {}
direction_dict['^'] = [0, 1]
direction_dict['V'] = [0, -1]
direction_dict['>'] = [1, 0]
direction_dict['<'] = [-1, 0]

position = [0, 0]
past_positions = []
past_positions.append(position[:])
loops = []
for n, d in enumerate(direction_list):
position[0] += direction_dict[d][0]
position[1] += direction_dict[d][1]
if position in past_positions:
idx = past_positions.index(position)
loops.append(direction_list[idx:n+1])
past_positions[idx] = ['X', 'X']
past_positions.append(position[:])
return loops``````

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.