Determine Whether One Point Can Reach Another
Company: NVIDIA
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Quick Answer: Determine whether a target point with positive integer coordinates can be reached from a starting point using two coordinate-addition moves. Account for values as large as 10^18, targets equal to the start, impossible coordinate relationships, and exact reachability.
Constraints
- sx, sy, tx, and ty are decimal strings for values from 1 through 10^18.
- All moves use exact positive-integer arithmetic.
Examples
Input: ('1', '1', '3', '5')
Expected Output: True
Explanation: Checks equality, repeated moves, unreachable gcd states, and exact large coordinates.
Input: ('1', '1', '2', '2')
Expected Output: False
Explanation: Checks equality, repeated moves, unreachable gcd states, and exact large coordinates.
Hints
- Work backward because the larger target coordinate identifies the last move.
- Replace repeated subtraction with a remainder, while handling a coordinate already equal to its start value.