FastPrepRotate List

Rotate List

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

Rotate the singly linked list to the right by k positions and return the new head.

Function

rotateRight(head: ListNode, k: int) → ListNode

Examples

Example 1

head = [1,2,3,4,5]k = 2return = [4,5,1,2,3]

The last two nodes move to the front.

Constraints

  • The list contains at most 10^5 nodes.
  • 0 <= k <= 10^9.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public ListNode rotateRight(ListNode head, int k) {
  // Write your code here.
}
head[1,2,3,4,5]
k2
expected[4,5,1,2,3]
Checking account…