Trains the technique from
LeetCode 1652Defuse the BombThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A mechanical dial carries n numbered slots arranged in a circle; ring[i] is the number engraved on slot i, and slot n - 1 sits immediately before slot 0 going clockwise. A service manual asks you to re-engrave the whole dial at once, using a single setting shift.
For every slot i, its new number is:
shift slots clockwise, when shift > 0;-shift slots anticlockwise, when shift < 0;0, when shift == 0.The counting wraps round the circle, and a slot never counts itself. Every new number is worked out from the numbers engraved before the rewrite, not from numbers written during it.
Return the list of new numbers, slot 0 first.
Example 1
Slot 0 reads slots 1 and 2, giving 7 + 1 = 8. Slot 1 reads slots 2 and 3, giving 1 + 4 = 5. Slot 2 wraps to slots 3 and 0, giving 4 + 5 = 9, and slot 3 wraps to slots 0 and 1, giving 5 + 7 = 12.
Example 2
Each slot takes the single number behind it, so slot 0 wraps back to slot 3 and reads 4, while slots 1, 2 and 3 read 5, 7 and 1.
Example 3
A setting of zero engraves 0 on every slot.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def rewrite_ring(ring: list[int], shift: int) -> list[int]:public int[] rewriteRing(int[] ring, int shift)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.