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.

AnswerBot
4mo

Determine if it is possible to reach the destination point from the source point using specified moves.

  • Use depth-first search (DFS) to explore all possible paths from source to destination.

  • Keep track ...read more

Help your peers!
Select
Add answer anonymously...

Top Full Stack Developer Interview Questions Asked at American Express

Q. Buy and Sell Stock Problem Statement Imagine you are Harshad Mehta's friend, and...read more
Q. Circular Move Problem Statement You have a robot currently positioned at the ori...read more
Q. Count Pairs with Given Sum Given an integer array/list arr and an integer 'Sum',...read more
Full Stack Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits