Reverse Additive Coordinate Moves

Quick Overview

Reverse Additive Coordinate Moves. From (sx,sy), a move replaces (x,y) by either (x,x+y) or (x+y,y).

Reverse Additive Coordinate Moves

Company: Virtu Financial

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem From (sx,sy), a move replaces (x,y) by either (x,x+y) or (x+y,y). Return whether the positive target (tx,ty) is reachable using zero or more moves. ```cpp class Solution { public: bool reachingPoints(int sx, int sy, int tx, int ty); }; ``` ### Examples **Example 1:** ```text sx = 2, sy = 3, tx = 7, ty = 5 Output: true Explanation: (2,3) -> (2,5) -> (7,5). ``` **Example 2:** ```text sx = 2, sy = 3, tx = 4, ty = 6 Output: false Explanation: The target has gcd2 while the starting gcd is1; addition preserves gcd. ``` ### Constraints - All four coordinates are integers between 1 and 1000000000 inclusive. ### Contract considerations Allow zero moves and retain all four original coordinates. ```hint Read the boundary condition When target coordinates differ, which one must have changed last? ``` ### Boundary reminders Allow zero moves and retain all four original coordinates.

Overview: Reverse Additive Coordinate Moves. From (sx,sy), a move replaces (x,y) by either (x,x+y) or (x+y,y).

Virtu Financial logo
Virtu Financial
Source window: 0–6 months · as of Oct 21, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

From (sx,sy), a move replaces (x,y) by either (x,x+y) or (x+y,y). Return whether the positive target (tx,ty) is reachable using zero or more moves.

class Solution {
public:
    bool reachingPoints(int sx, int sy, int tx, int ty);
};

Examples

Example 1:

sx = 2, sy = 3, tx = 7, ty = 5
Output: true
Explanation: (2,3) -> (2,5) -> (7,5).

Example 2:

sx = 2, sy = 3, tx = 4, ty = 6
Output: false
Explanation: The target has gcd2 while the starting gcd is1; addition preserves gcd.

Constraints

  • All four coordinates are integers between 1 and 1000000000 inclusive.

Contract considerations

Allow zero moves and retain all four original coordinates.

Boundary reminders

Allow zero moves and retain all four original coordinates.