ring are arranged in a circle: the first element follows the last one, and the last one comes before the first.
For every position i, independently of the others:
- if ring[i] > 0, count ring[i] steps to the right from position i;
- if ring[i] < 0, count |ring[i]| steps to the left;
- if ring[i] == 0, stay where you are.
Put the number found where you stop into cell i of the answer (for a zero that is the 0 itself). Return a new array of the same length, always reading values from the original ring.ring=[2, -1, 0, 5] → [0, 2, 0, 2]
From position 0, two steps right lead to position 2, which holds 0. From position 1, one step left leads to position 0, which holds 2. Position 2 holds 0, so it stays 0. From position 3, five steps right around a ring of four lead to position 0, which holds 2.
ring=[-3, 4] → [4, 4]
From position 0, three steps left around a ring of two lead to position 1, which holds 4. From position 1, four steps right come back to position 1, which holds 4.
ring=[2, -1, 0, 5]
[0, 2, 0, 2]
Run checks the first 3 tests in your browser. Submit checks all 128 tests on the server, hidden ones included.