Lattice Points on a Segment
Return how many points with whole number coordinates lie on the straight segment from (x1, y1) to (x2, y2), counting both endpoints. If the two endpoints are the same point, the answer is 1.
Example 1
x1 0
y1 0
x2 4
y2 2
returns 3
(0,0), (2,1) and (4,2).
Constraints
- Coordinates are between -50 and 50
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.