Tap here to switch tabs
Problem
Submissions

Problem: Reach a Number

med
30 min
Try to solve the Reach a Number problem.

Statement

You start at position 00 on an infinite number line. On the ii th move, you must walk exactly ii steps, and you may choose to move either left or right.

Given an integer target, return the minimum number of moves required to land exactly on position target.

Constraints:

  • −109≤-10^9 \leq target ≤109\leq 10^9

  • target ≠0\neq 0

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Reach a Number

med
30 min
Try to solve the Reach a Number problem.

Statement

You start at position 00 on an infinite number line. On the ii th move, you must walk exactly ii steps, and you may choose to move either left or right.

Given an integer target, return the minimum number of moves required to land exactly on position target.

Constraints:

  • −109≤-10^9 \leq target ≤109\leq 10^9

  • target ≠0\neq 0