Tap here to switch tabs
Problem
Submissions

Problem: Ant on the Boundary

med
30 min
Try to solve the Ant on the Boundary problem.

Statement

An ant starts at a boundary at position 00. You are given an array of non zero integers nums.

At each step, the ant moves according to the value of nums[i]. If nums[i] > 0, the ant moves to the right by nums[i] units. If nums[i] < 0, the ant moves to the left by ∣|nums[i]∣| units.

Return the total number of times the ant returns to the boundary.

Constraints:

  • 1≤1 \leq nums.length ≤100\leq 100

  • −10≤-10 \leq nums[i] ≤10\leq 10

  • nums[i] ≠0\neq 0

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Ant on the Boundary

med
30 min
Try to solve the Ant on the Boundary problem.

Statement

An ant starts at a boundary at position 00. You are given an array of non zero integers nums.

At each step, the ant moves according to the value of nums[i]. If nums[i] > 0, the ant moves to the right by nums[i] units. If nums[i] < 0, the ant moves to the left by ∣|nums[i]∣| units.

Return the total number of times the ant returns to the boundary.

Constraints:

  • 1≤1 \leq nums.length ≤100\leq 100

  • −10≤-10 \leq nums[i] ≤10\leq 10

  • nums[i] ≠0\neq 0