given a list rotate the list to the right by k places where k is nonnegative for example given 12345null and k 2 return 45123null definition for singlylinked list class listnodeobject def initself x self val x self next none type head listnode type k int rtype listnode count length of the list make it circular rotate until lengthk definition for singly linked list class listnode object def __init__ self x self val x self next none type head listnode type k int rtype listnode count length of the list make it circular rotate until length k
def rotate_right(head, k):
    
    if not head or not head.next:
        return head
    current = head
    length = 1
    
    while current.next:
        current = current.next
        length += 1
    
    current.next = head
    k = k % length
    
    for i in range(length-k):
        current = current.next
    head = current.next
    current.next = None
    return head