Rotate a Linked List to the Right
Updated
Problem statement
Given the head head of a singly linked list and a nonnegative integer k, move the final node to the front k times and return the new head.
A complete rotation preserves order. An empty list returns an empty list. The resulting list must terminate; it must not contain a cycle.
Function
rotateRight(head: ListNode, k: int) → ListNodeExamples
Example 1
head = [1,2,3,4,5]k = 2return = [4,5,1,2,3]Moved or new
The final two nodes become the first two, without reversing them.
Example 2
head = [0,1,2]k = 4return = [2,0,1]Moved or new
Four rightward rotations equal one rotation for a three-node list.
Example 3
head = []k = 7return = []Rotating an empty list leaves it empty.
Constraints
- The list contains
0to500nodes. -100 <= Node.val <= 100.0 <= k <= 2 * 10^9.
More NVIDIA Phone Screen questions
- Network Layer Execution OrderPHONE SCREEN · Seen Nov 2026
- Paged KV Cache AccessPHONE SCREEN · Seen Nov 2026
- Sliding Window Attention over a KV CachePHONE SCREEN · Seen Nov 2026
- Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
- Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
- Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
- Least Frequently Used CachePHONE SCREEN · Seen Oct 2026
- Parallel String Counts with a Custom Hash TablePHONE SCREEN · Seen Oct 2026
- Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
- Streaming Top-K Frequent ElementsPHONE SCREEN · Seen Aug 2026
Similar questions at other companies
- LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
- LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Convert a Sorted Linked List to a Balanced BSTMeta · PHONE SCREENMeta interview questions
- LRU CacheAthenahealth · PHONE SCREEN
- LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
- Balanced Session ManagerPalantir · PHONE SCREENPalantir interview questions
- LRU CacheGimlet Labs · PHONE SCREEN
- LRU CacheBNSF Railway · PHONE SCREENBNSF Railway interview questions
- Max Frequency TrackerProcol · PHONE SCREEN
- LRU Cache Operation SequenceCARS24 · PHONE SCREEN