## A9 Interview Question for SDE-2s

Country: United States

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

Basic solution would be to recur for both possibilities. A function can be written like below.
Assuming x & y is current location and dx & dy are destination.

``````bool isReachable(int x, int y, int dx, int dy)
{
// Destination reached
if((x == dx) && (y == dy))
return true;

// Limit exceeds
if((x > dx) || (y > dy))
return false;

// Only two ways left to traverse
return isReachable(x + y, y, dx, dy) || isReachable(x, x + y, dx, dy);
}``````

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

What if we need to handle negative numbers too? Does it look feasible?

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

What if we need to handle negative numbers too? Does it look feasible?

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

Here is my python code

``````def isReachable(self, a,b,c,d):
def __move(a,b):

if a  == c and b  == d :
return True

if ( a < c and b > 0 or a > c and b <0):
return __move(a+b, b)
else:
return __move(a, a+b)

return __move(a, b)``````

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.