Skip to content

Practice Ant on the Boundary

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

Easy#3028
LeetCode Problem

Ant on the Boundary

Problem Statement

Start at position 0. For each value in nums, move that many units right when positive or its absolute value left when negative. Count only moves ending exactly at 0, not a crossing during a move. Return that count; the initial position does not count.

Source: Ant on the Boundary on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [2,3,-5]
Output
1

# Example 2

Input
nums = [3,2,-3,-4]
Output
0

Constraints

1 <= nums.length <= 100
-10 <= nums[i] <= 10
nums[i] != 0

Related LeetCode Problems

Practice more problems similar to Ant on the Boundary.

Review your practice with PhantomCodeAI

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