data_structures.arrays.rotate_array

Attributes

examples

Functions

rotate_array(→ list[int])

Rotates a list to the right by steps positions.

Module Contents

data_structures.arrays.rotate_array.rotate_array(arr: list[int], steps: int) list[int]

Rotates a list to the right by steps positions.

Parameters: arr (List[int]): The list of integers to rotate. steps (int): Number of positions to rotate. Can be negative for left rotation.

Returns: List[int]: Rotated list.

Examples: >>> rotate_array([1, 2, 3, 4, 5], 2) [4, 5, 1, 2, 3] >>> rotate_array([1, 2, 3, 4, 5], -2) [3, 4, 5, 1, 2] >>> rotate_array([1, 2, 3, 4, 5], 7) [4, 5, 1, 2, 3] >>> rotate_array([], 3) []

data_structures.arrays.rotate_array.examples