Skip to content
Onsite

Minimum Moves to Reach B

EasyP3Coding

A move adds either 1 or 2 to the current value. Return the minimum number of moves needed to turn a into b, where b >= a. If they are already equal, no move is needed.

Example 1

Input
a = 1, b = 4
Output
2
Why
Two moves: +2 then +1.

Example 2

Input
a = 5, b = 5
Output
0

Example 3

Input
a = 2, b = 3
Output
1
Why
One +1 move.

Constraints

  • 0 <= a <= b <= 10^9

Hints

Run checks the 3 visible tests, Submit all 8.