Validate Linked List Pointer Ordering
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The detail that matters in this Bloomberg problem from December 2020 is that the list lives in arrays, and the backward and forward pointers refer to node indices, not positions. So index 2 isn't "third in the list" unless the list says so. It's a linked-list traversal question with a lookup twist. Walk from head, record each node's position, then check every pointer against those positions. If you blank on the setup during the OA, StealthCoder runs invisibly as a safety net and gives you the approach in real time.
The problem
Arrays encode one singly linked list: next[i] is the next node index and head its first node. Every node is visited exactly once. Auxiliary backward[i] and forward[i] are node indices or -1 for null. Return true if every non-null backward pointer targets an earlier list position and every non-null forward pointer targets a later position. Function validPointerOrder(next: int[], backward: int[], forward: int[], head: int) → boolean Examples Example 1 next = [1,2,-1] backward = [-1,0,0] forward = [2,2,-1] head = 0 return = true All auxiliary pointers point in their required list direction. Constraints All arrays have equal length. All nonnegative indices are valid.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is two passes. Pass one: start at head, follow next[], and fill pos[node] = step count. Every node is visited exactly once, so pos covers all nodes and you don't need cycle handling beyond the guarantee. Pass two: for each node i, if backward[i] != -1, require pos[backward[i]] < pos[i]. If forward[i] != -1, require pos[forward[i]] > pos[i]. Return false on the first violation, true otherwise. The common pitfall is comparing raw indices instead of list positions. In the example, next = [1,2,-1] makes indices match positions, which hides the bug. Another trap is treating a pointer to itself as valid. Equal positions fail both strict checks. It's O(n) time and O(n) space. If you freeze on the position mapping during the live OA, StealthCoder is the hedge that surfaces the two-pass structure so you can type it out cleanly.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Validate Linked List Pointer Ordering 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
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.
Validate Linked List Pointer Ordering FAQ
How hard is this Bloomberg problem really?+
Easy to low-medium. There's no clever algorithm, just a traversal and a lookup array. The difficulty is reading the statement carefully and realizing pointers are node indices that must be translated into list positions before comparing.
What's the trick to solving it?+
Build a pos array by walking from head along next[]. Then for each node, compare pos of its backward and forward targets against its own pos. Skip -1 values. Strict inequality, so a self-pointer fails.
What's the most common mistake?+
Comparing raw indices instead of positions. It passes the sample because next = [1,2,-1] lines indices up with positions, then fails on any list where the order is shuffled. Always map through pos first.
What's the time and space complexity?+
O(n) time, since you traverse once and check once. O(n) space for the position array. You can't really avoid the extra array, because you need random access to each node's list position.
How do I prepare for this in 48 hours?+
Practice array-encoded linked list traversal and writing a pos map from a walk. Then code this exact check from scratch twice. Test with a shuffled next array, -1 pointers, and a pointer to the node itself.