Rotate the elements of an array by d positions to the left. Let us initially look at an example.

By ayush goel in 22 Sep 2023 | 03:51 pm
ayush goel

ayush goel

Student
Posts: 346
Member since: 21 Sep 2023

Rotate the elements of an array by d positions to the left. Let us initially look at an example.

22 Sep 2023 | 03:51 pm
0 Likes
divas goyal

divas goyal

Student
Posts: 453
Member since: 22 Sep 2023

def rotate_left(arr, d):

    n = len(arr)

    d = d % n  # Handle cases where d is larger than the array size

    return arr[d:] + arr[:d]


arr = [1, 2, 3, 4, 5]

d = 2

rotated_arr = rotate_left(arr, d)

print(rotated_arr)


23 Sep 2023 | 02:59 pm
0 Likes

Report

Please describe about the report short and clearly.