Skip to content

Practice Reach a Number

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#754
LeetCode Problem

Reach a Number

Problem Statement

Start at zero on an infinite number line. On move i, starting at 1, move exactly i positions either left or right. Given target, return the fewest moves needed to land exactly on it.

Source: Reach a Number on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
target = 2
Output
3

# Example 2

Input
target = 3
Output
2

Constraints

-10^9 <= target <= 10^9
target != 0

Related LeetCode Problems

Practice more problems similar to Reach a Number.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.