A company may process ordered linked-list records that must be shifted when routing priorities change. Given the head of a singly linked list and a non-negative integer k, rotate the list to the right by k positions and return the new head.
A right rotation moves the final node to the front. Repeating this operation k times should produce the same result as one rotation by k % length positions.
Implement rotate_right(head, k), where head is either None or a ListNode with integer field val and pointer field next. Return the new ListNode head. The list must be rearranged in place, without creating replacement data nodes. In serialized examples and test cases, a linked list is represented by an array of node values.
def rotate_right(head, k):