You are given an integer array
nums
that represents a circular array. Your task is to create a new arrayresult
of the same size, following these rules:For each index
i
(where0 <= i < nums.length
), perform the following independent actions:
- If
nums[i] > 0
: Start at indexi
and movenums[i]
steps to the right in the circular array. Setresult[i]
to the value of the index where you land.- If
nums[i] < 0
: Start at indexi
and moveabs(nums[i])
steps to the left in the circular array. Setresult[i]
to the value of the index where you land.- If
nums[i] == 0
: Setresult[i]
tonums[i]
.Return the new array
result
.Note: Since
nums
is circular, moving past the last element wraps around to the beginning, and moving before the first element wraps back to the end.
1 | package main |