An image carousel has count slides, numbered 0 to count - 1. It wraps around: moving forward from the last slide goes to slide 0, and moving back from slide 0 goes to the last slide.
Write wrapIndex(index, step, count) that returns the slide shown after moving step slides from slide index. A negative step moves backward. The result must be between 0 and count - 1.
Input: index = 4, step = 1, count = 5 Output: 0
Slide 4 is the last of 5, so one step forward wraps to slide 0.
Input: index = 0, step = -1, count = 5 Output: 4
One step back from slide 0 wraps to the last slide, 4.
1 <= count <= 10^60 <= index < count-10^12 <= step <= 10^12Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #643 Wrap a Carousel Index. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.