Reach the Destination Problem Statement
You are given a source point (sx, sy) and a destination point (dx, dy). Determine if it is possible to reach the destination point using only the following valid moves:
- (a, b) -> (a + b, b)
- (a, b) -> (a, a + b)
Input:
The input consists of:
The first line contains an integer ‘T’, the number of test cases. Each test case consists of a single line with four space-separated integers sx, sy, dx, dy representing the source point (sx, sy) and the destination point (dx, dy).
Output:
For each test case, return the boolean value true if it is possible to reach the destination point from the source point using only the specified moves, otherwise return false. The output for each test case should be on a separate line.
Example:
Input:
1
1 1 3 5
Output:
true
Explanation:
You can move from (1, 1) -> (1, 2) -> (3, 2) -> (3, 5), hence the destination is reachable.
Constraints:
- 1 <= T <= 100
- 1 <= x, y <= 3000
Note: You do not need to print anything. Implement the function to solve the problem.
Be the first one to answer
Add answer anonymously...
Top American Express Full Stack Developer interview questions & answers
Popular interview questions of Full Stack Developer
>
American Express Full Stack Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app