CJCoding With Joseph
15free / daySign inCreate account

Rotate Left By Slicing

Write rotate_left(values: list[int], k: int) -> list[int] that returns a new list with the first k items moved to the end, so rotating 1 2 3 4 5 by 2 gives 3 4 5 1 2. Use two slices joined with +, and first reduce k with the remainder operator % by the length so that a k larger than the list wraps around; an empty list is returned as is. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: two lines, a space-separated list of integers (possibly empty) and then k; the tests print the list your function returns.

Expected Output:

[3, 4, 5, 1, 2]

= newline. The output ends with a newline — print one after the last line.

Hints2 available
Topics:
Data Structures & AlgorithmsSlicing
📥 Auto-Input:
1 2 3 4 5\n2\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.