Rotate a Linked Rotation Schedule Right by K Positions
Last updated: November 29, 2026
Quick Overview
An on-call rotation is a singly linked list of engineers. Rotate it to the right by k positions, where k can be far larger than the list length, and return the new head.
0
0
0 solved
An on-call rotation is a singly linked list of engineers. Rotate it to the right by k positions, where k can be far larger than the list length, and return the new head.
A Google technical screen question about pointer surgery plus a modular arithmetic detail. Interviewers deliberately give huge k to see if you reduce it modulo the length rather than rotating one step at a time.
What the Interviewer Expects
- Compute the length and the tail in one pass
- Reduce k modulo the length
- Close the list into a ring and break it at the right place
- Return early when k % n == 0
- O(n) time, O(1) space
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Rotate left instead.
- Rotate a doubly linked list in O(min(k, n - k)).
- Apply many rotations and answer who is on call on day d.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: head, non-negative integer k (possibly huge).
- Output: head after moving the last k % n nodes to the front, in order.
- O(n) time, O(1) space....
High-Level Design
Rotating right by k moves the last k nodes to the front. Rotating by n is a no-op, so only k % n matters, which turns a potentially billion-step loop into at most n. Walk once to find the length n and...