## Flipkart Interview Question for SDE-2s

Country: United States

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

``````import numpy as np

(ni, nj) = (3,3)
js = np.ones([ni, nj], dtype = 'int')
k = 3
start = (0,0)
destination = (0, nj - 1)

def calculate_descendants(current, k, ni, nj):
for i in range(max(current[0] - k, 0), min(current[0] + k, ni) + 1):
for j in range(current[1], min(current[1] + k, nj) + 1):
if abs(i - current[0]) + abs(j - current[1]) == k:
yield (i, j)

def minimum_path(start, destination, js, ni, nj):
current = start
discovered = [current]
processed = list()
parent = {current: None}
done = False
while discovered != [] and not done:
current = discovered.pop(0)
processed.append(current)
for descendant in calculate_descendants(current, js[current[0], current[1]], ni - 1, nj - 1):
if descendant not in processed:
discovered.append(descendant)
parent[descendant] = current
if descendant == destination:
done = True
if done:
current = destination
path = [current]
while parent[current] != None:
current = parent[current]
path.insert(0, [current])
print path
else:

minimum_path(start, destination, js, ni, nj)``````

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

Could you please explain the logic?

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

please tell me for that situation can dx or dy be negative as it'll follow dx+dy=k,
i.e dy will be more than k and dx will negative of difference of dy and k.

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

Imagine the graph where the vertices are the stones and the edges connect two stones that we can jump. Perform breadth first search, until you hit the destination point.

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.