Challenge: Right Rotate List

Given a list, can you rotate its elements by one index from right to left? Implement your solution in Python and see if your code runs successfully.

Problem Statement

Implement a function right_rotate(lst, k) which will rotate the given list by k. This means that the right-most elements will appear at the left-most position in the list and so on. You only have to rotate the list by one element at a time.

Input

A list and a positive number by which to rotate that list

Output:

The given list rotated by k elements

Sample Input

lst = [10,20,30,40,50]
k = 3

What if the given input k is greater than the length of the lst?

Sample Output

lst = [30,40,50,10,20]

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.