Ctrl K

Jumps Around the Ring

Easy
The numbers of 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.
Example 1
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.

Example 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.

Constraints
  • 1 ≤ len(ring) ≤ 100
  • -100 ≤ ring[i] ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsHow Long the Light Stayed On EasyRepack the Tray EasyQuiz Score Log EasyMirror and Negate a Bitmap EasySwap Rows and Columns Easy
loading Python…
Input
ring=[2, -1, 0, 5]
Expected
[0, 2, 0, 2]

Run checks the first 3 tests in your browser. Submit checks all 128 tests on the server, hidden ones included.