Traverse an Up-Down-Right Pointer Structure
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Each node in this Bloomberg OA from September 2020 carries three pointers, up, down and right, and any of them can be -1. You start at one index and have to collect every value you can reach. It looks like a weird grid or linked structure, but it's plain graph traversal with a sort at the end. If you've got an invite and 48 hours, this one is quick to nail. If you blank on the day, StealthCoder runs invisibly on your desktop as a safety net and hands you the traversal when your head goes empty.
The problem
Node i has value values[i] and up, down, and right target indices or -1. Starting at start, follow any of those directed pointers. Return every reachable node value once in ascending order. Function accessibleValues(values: int[], up: int[], down: int[], right: int[], start: int) → int[] Examples Example 1 values = [1,2,3,4,5,6,7,8,9,10,11,12] up = [-1,0,1,-1,-1,-1,-1,6,-1,-1,9,-1] down = [-1,-1,3,-1,5,-1,-1,8,-1,-1,-1,-1] right = [-1,-1,4,-1,7,-1,-1,10,-1,-1,11,-1] start = 2 return = [1,2,3,4,5,6,7,8,9,10,11,12] Starting at value 3 reaches every displayed node. Constraints All arrays have equal length. The reachable pointer graph is acyclic.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Treat each index as a graph node with up to three outgoing edges: up[i], down[i], right[i]. Skip any edge that equals -1. Run DFS or BFS from start, mark visited indices, and collect values[i] for each one. Then sort the collected values ascending and return them. The constraints say the reachable graph is acyclic, but a node can still be reached by two different paths, so a visited set stops duplicate values and repeated work. The common pitfall is forgetting the visited check and emitting a value twice, or returning values in traversal order instead of sorted order. Another slip is treating the arrays as a grid and inventing coordinates. Use an iterative stack if you worry about recursion depth. Complexity is O(n log n) because of the sort. If the live assessment rattles you, StealthCoder can surface this exact approach while you type.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Traverse an Up-Down-Right Pointer Structure 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Traverse an Up-Down-Right Pointer Structure FAQ
How hard is this Bloomberg OA question really?+
Easy to medium. The graph is given as three index arrays, so there's no parsing trick. If you know DFS with a visited set and remember to sort at the end, you can finish it in a few minutes.
What's the trick to this problem?+
Treat it as a directed graph where each node has up to three edges. Skip -1 targets, traverse from start, track visited indices, then sort the collected values. The weird up/down/right naming is just decoration.
Do I need a visited set if the graph is acyclic?+
Yes. Acyclic means no loops, but two paths can still lead to the same node. Without a visited set you'd add that value twice, and the problem says to return each value once.
Should I use DFS or BFS?+
Either works and gives the same set of reachable nodes. Since you sort afterward, order of visit doesn't matter. Pick the one you can write fastest without bugs. An iterative stack avoids recursion depth worries.
How do I prepare for this in 48 hours?+
Write a graph traversal over an adjacency structure given as arrays, with a visited set and a final sort. Do it two or three times from memory. Also practice edge cases like start having all -1 pointers.