Reaching Points - Problem
Given four integers sx, sy, tx, and ty, return true if it is possible to convert the point (sx, sy) to the point (tx, ty) through some operations, or false otherwise.
The allowed operation on some point (x, y) is to convert it to either (x, x + y) or (x + y, y).
Input & Output
Example 1 — Reachable Target
$
Input:
sx = 1, sy = 1, tx = 3, ty = 5
›
Output:
true
💡 Note:
Path exists: (1,1) → (1,2) → (3,2) → (3,5). We can apply operations (1,1+1)=(1,2), then (1+2,2)=(3,2), then (3,3+2)=(3,5).
Example 2 — Unreachable Target
$
Input:
sx = 1, sy = 1, tx = 2, ty = 2
›
Output:
false
💡 Note:
From (1,1) we can only reach (1,2) or (2,1), but never (2,2). Both coordinates cannot increase simultaneously.
Example 3 — Same Point
$
Input:
sx = 1, sy = 1, tx = 1, ty = 1
›
Output:
true
💡 Note:
Source and target are the same point, so no operations needed.
Constraints
- 1 ≤ sx, sy, tx, ty ≤ 109
Visualization
Tap to expand
Understanding the Visualization
1
Input
Source (sx,sy) and target (tx,ty) coordinates
2
Process
Apply operations (x,x+y) or (x+y,y) to reach target
3
Output
Return true if target is reachable, false otherwise
Key Takeaway
🎯 Key Insight: Working backwards with modulo operations is exponentially faster than forward exploration
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code