Reaching Points
Real-world version: Growing a Pair by Adding One to the OtherThe statement here is our own: the same inputs, outputs and technique.
A pair of whole numbers starts as (sx, sy). One step replaces the pair either by its first number plus its second alongside the second, or by the first alongside the first plus the second.
Return true when some sequence of steps turns the starting pair into (tx, ty).
Examples
Example 1
- Input
- sx = 1, sy = 1, tx = 3, ty = 2
- Output
- true
From 1 and 1, growing the second gives 1 and 2, then growing the first gives 3 and 2.
Example 2
- Input
- sx = 1, sy = 1, tx = 2, ty = 2
- Output
- false
Any step from 1 and 1 makes the two numbers different, and no later step can bring them level again, so an equal pair is out of reach.
Example 3
- Input
- sx = 2, sy = 2, tx = 4, ty = 2
- Output
- true
Growing the first number by the second takes 2 and 2 straight to 4 and 2.
Constraints
- 1 <= sx <= 10^9
- 1 <= sy <= 10^9
- 1 <= tx <= 10^9
- 1 <= ty <= 10^9
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def reaching_points(sx: int, sy: int, tx: int, ty: int) -> bool:public boolean reachingPoints(int sx, int sy, int tx, int ty)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 16 test cases: 16 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Find Greatest Common Divisor of ArrayReal-world version: Sprocket Extremes Common DivisorEasy
- Greatest Common Divisor of StringsReal-world version: Longest Shared Ribbon TileEasy
- Water and Jug ProblemReal-world version: Measuring Out an Exact Amount With Two CansMedium
- Find the Number of Subsequences With Equal GCDReal-world version: Matched Gear BenchesHard