Rotate List
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on Bloomberg's Rotate List is rotating k times literally. With k up to 10^9 and a list of up to 10^5 nodes, that loop times out fast. Bloomberg's OA was reported in January 2021, and this one is a linked list problem dressed up as a rotation problem. The trick is small and the edge cases are where people bleed points. If you've got an invite and 48 hours, learn the length-and-reconnect move cold. StealthCoder sits invisibly on your screen during the live OA as a safety net if your mind goes blank on the pointer work.
The problem
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 = 2 return = [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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The pattern is a linked list with a length trick. Walk the list once to get the length n and the tail. Reduce k with k % n, since rotating by n returns the same list. If the result is 0, return head untouched. Otherwise, connect the tail to the head to form a ring, then walk n - k - 1 steps from the head to find the new tail. The next node is the new head. Set the new tail's next to null. The common pitfalls are skipping the modulo, forgetting the empty or single-node list, and off-by-one errors on the walk. Never copy values into an array unless you're fine with extra space. If you freeze on the pointer math mid-assessment, StealthCoder can hand you the clean version while you keep your composure.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Rotate List cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as rotate list. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Rotate List FAQ
What's the trick in Rotate List?+
Don't rotate k times. Compute the length n, take k % n, make the list circular by linking the tail to the head, then cut the ring at position n - k % n. That's one pass to measure and one to find the cut. O(n) time, O(1) space.
How hard is this Bloomberg OA question really?+
It's a medium on paper but easy once you know the ring trick. The difficulty is in the edge cases, not the idea. Expect to lose points on empty lists, k equal to a multiple of n, and off-by-one errors, not on the core algorithm.
Why does k go up to 10^9 in the constraints?+
It's a hint that simulating k rotations is wrong. Since rotating by the list length gives you the same list, only k % n matters. That bound exists to punish the naive loop with a timeout, so reduce k first.
What edge cases should I test before submitting?+
Test an empty list, a single node, k = 0, k equal to n, and k larger than n. Also test k = n + 1, which should behave like k = 1. Make sure the new tail's next is set to null, or you'll create a cycle and the checker will hang.
How do I prepare for this in 48 hours?+
Write it from scratch three times without looking. Focus on the pointer walk: find the tail, link the ring, step n - k - 1 times, cut. Then do a couple of related linked list problems like reversing and finding the middle so the pointer handling feels automatic.