You are given an integer array
numsthat represents a circular array. Your task is to create a new arrayresultof 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 indexiand 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 indexiand 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
numsis 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 |