
Rotate a shift schedule
easyRotate a shift schedule
Walmart Python Interview Question
Walmart rotates its weekly shift schedule so every associate takes a turn at the early shift.
Write a function rotate(shifts, steps) that moves every item in the list to the right by the given number of steps, with items that fall off the end wrapping around to the front. The number of steps can be larger than the length of the list.
Asked of
- Data Analyst
- Data Engineer
- Data Scientist
- ML Engineer
- AI Engineer
Example 1
Input
shifts = ["Ana", "Ben", "Cal", "Dee", "Eva"], steps = 1
Output
["Eva", "Ana", "Ben", "Cal", "Dee"]
Example 2
Input
shifts = ["Ana", "Ben", "Cal"], steps = 4
Output
["Cal", "Ana", "Ben"]
Explanation
In the first example, rotating by 1 moves "Eva" from the end to the front. In the second example, rotating 3 names by 4 steps is the same as rotating by 1.
Submit also runs 4 hidden test cases that check edge cases.
Company
Walmart
Difficulty
easy
Topic
lists
Language
Python
Your code
Loading Python in the background. You can start writing.