Trains the technique from
LeetCode 754Reach a NumberThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A pointer sits at position 0 on a line of whole numbers. On move number k, counting the first move as one, the pointer travels exactly k places, and each move may be taken to the left or to the right.
Return the fewest moves that leave the pointer sitting exactly on marker.
Example 1
One move right, then one left, then one right lands on the marker after three moves. Two moves cannot manage it, because they land on one place away from the start or three away, never four.
Example 2
A single move to the left arrives straight away.
Example 3
Four moves all rightward reach ten, one short, and no turning of them can shave a single place off, since turning a move around always shifts the finish by an even amount. Five moves rightward overshoot by four, and turning the second move around takes exactly four back.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def reach_number(marker: int) -> int:public int reachNumber(int marker)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.