Skip to content
Onsite

Number Line Jumps

EasyP3Coding

Two kangaroos are on a number line. The first starts at x1 and jumps v1 units per jump; the second starts at x2 and jumps v2 units per jump. Both jump at the same time, and jump lengths are never negative.

Return true if there is a non-negative whole number of jumps t after which both kangaroos are at the same position, otherwise false. t = 0 counts, so kangaroos that start at the same position meet.

Example 1

Input
x1 = 0, v1 = 3, x2 = 4, v2 = 2
Output
true
Why
After 4 jumps both are at 12.

Example 2

Input
x1 = 0, v1 = 2, x2 = 5, v2 = 3
Output
false
Why
The first is always behind the second and slower, so they never meet.

Example 3

Input
x1 = 0, v1 = 3, x2 = 4, v2 = 3
Output
false

Constraints

  • 0 <= x1, x2 <= 10^4
  • 0 <= v1, v2 <= 10^4

Hints

Run checks the 3 visible tests, Submit all 10.