Practice Minimum Moves to Reach Target in Grid
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Starting at (sx, sy), a move from (x, y) computes m = max(x, y) and either increases x by m or increases y by m. Return the fewest moves to reach exactly (tx, ty), or -1 if impossible.
Source: Minimum Moves to Reach Target in Grid on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
sx = 1, sy = 2, tx = 5, ty = 4
Output
2
# Example 2
Input
sx = 0, sy = 1, tx = 2, ty = 3
Output
3
# Example 3
Input
sx = 1, sy = 1, tx = 2, ty = 2
Output
-1
Constraints
0 <= sx <= tx <= 10^9
0 <= sy <= ty <= 10^9
Related LeetCode Problems
Practice more problems similar to Minimum Moves to Reach Target in Grid.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.