


(a, b) -> (a + b, b)
(a, b) -> (a, a + b)
For the coordinates, source point = (1, 1) and destination point = (3, 5)
The output will be true as the destination point can be reached using the following sequence of moves:
(1, 1) -> (1, 2) -> (3, 2) -> (3, 5)
The first line of input contains an integer ‘T’ representing the number of test cases. Then the test cases follow.
The only line of each test case contains four space-separated integers sx, sy, dx, and dy where sx, sy represents the coordinates of the source point and dx, dy represents the coordinates of the destination point.
For each test case, return the boolean true if the destination point can be reached from the source point using only the desired moves, else return false.
The output for each test case is to be printed on a separate line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= x, y <= 3000
Where ‘T’ is the number of test cases and ‘x’, ‘y’ are the coordinates of the given points.
Time Limit: 1sec
The naive approach to solve this problem is to consider each and every possible move until we reach the destination.
This can be done using recursion. Below is the algorithm:
The main idea of this approach is to iterate backward from the destination (dx, dy). We can determine which coordinate (x or y of destination point) was last changed, by selecting the larger of two. This will reduce the time complexity from exponential to linear since we are making just one recursive call for each valid pair of coordinates.
This can be done using recursion. Below is the algorithm:
Sorted Doubly Linked List to Balanced BST
Longest Substring with K-Repeating Characters
Expression Add Operators
Gray Code Transformation
Count of Subsequences with Given Sum