Skip to content

Commit 43b6c5e

Browse files
committed
reviewed
1 parent 6e1467d commit 43b6c5e

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
def rotate_array(arr, k):
1+
def rotate_array(arr: list[int], k: int) -> list[int]:
22
"""
33
Rotates the array to the right by k steps
44
55
Args:
6-
arr(list): The input array
7-
k(int): Number of steps to rotate
6+
arr (list[int]): The input array.
7+
k (int): Number of steps to rotate.
88
99
Returns:
10-
list: Rotated array
10+
list[int]: Rotated array.
11+
12+
Examples:
13+
>>> rotate_array([1, 2, 3, 4, 5], 2)
14+
[4, 5, 1, 2, 3]
15+
>>> rotate_array([1, 2, 3], 0)
16+
[1, 2, 3]
17+
>>> rotate_array([], 3)
18+
[]
1119
"""
1220
n = len(arr)
1321
k = k % n if n else 0
@@ -21,5 +29,5 @@ def rotate_array(arr, k):
2129

2230
if __name__ == "__main__":
2331
arr = [1, 2, 3, 4, 5, 6, 7, 8]
24-
k = 3
25-
print("Rotated array: ", rotate_array(arr, k))
32+
steps = 3
33+
print("Rotated array: ", rotate_array(arr, steps))

0 commit comments

Comments
 (0)