Recover Corrupted Master Page
Reported by candidates from Microsoft's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Microsoft OA reported in February 2026 dresses up a simple set problem as a storage system story. Page 0 is corrupted, and you rebuild the list of file heads from the rest. It's a hash-table problem at heart, and the trap is a detail the examples barely hint at: which pages count as pointers. If you read it fast, you'll write something that passes both samples and dies on the hidden tests. If you blank during the live OA, StealthCoder is the invisible safety net that reads the problem and hands you a clean solution.
The problem
A storage system keeps files as linked lists of pages. Each page has: a page offset or id, an empty bit indicating whether the page is unused, and the offset of the next page in the same file, or an EOF sentinel. Page 0 is the master page. It normally stores the starting offsets, or heads, of all file chains. Page 0 has been corrupted, and you need to reconstruct it. You are given pages, where each row is [id, emptyBit, next]. emptyBit is 1 for an empty page and 0 for a used page. next is the next page offset, or -1 for EOF. Return the sorted list of starting offsets for all file chains. A starting offset is a used page id that is not pointed to by the next field of any other used page. Function recoverMasterPage(pages: int[][]) → int[] Examples Example 1 pages = [[1,0,3],[2,0,5],[3,0,10],[4,1,-1],[5,0,-1],[10,0,-1]] return = [1,2] The used chains are 1 -> 3 -> 10 and 2 -> 5. Page 4 is empty, so it is ignored. The recovered master page offsets are [1,2]. Example 2 pages = [[7,0,-1],[3,0,4],[4,0,-1],[9,1,-1]] return = [3,7] Page 4 is pointed to by page 3, so it is not a head. Pages 3 and 7 are used and not pointed to by any used page. Constraints 1 <= pages.length pages[i].length == 3 pages[i][1] is either 0 or 1. pages[i][2] == -1 or pages[i][2] is a page offset.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: a head is a used page (emptyBit 0) that no other used page points to. So make one pass over the pages, and add next to a set whenever the page is used and next isn't -1. Then make a second pass and collect the ids of used pages that aren't in the set. Sort and return. The edge case that breaks a naive solution is pointers from empty pages. An empty page's next field must be ignored, even if it holds a real offset, because the statement says 'pointed to by any used page'. Also skip -1 so you don't treat EOF as an id. Don't assume the input is sorted, and don't assume ids are contiguous or that page 0 is present. Complexity is O(n log n) from the sort. If you freeze on the empty-pointer rule during the live OA, StealthCoder is there to catch it.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Recover Corrupted Master Page 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 by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Microsoft's OA.
Microsoft reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Recover Corrupted Master Page FAQ
How hard is Recover Corrupted Master Page really?+
Easy once you see it. It's a set lookup plus a sort. The difficulty is in the wording, not the algorithm. Most failures come from counting pointers from empty pages or forgetting to filter out -1 sentinels.
What's the trick to this Microsoft OA question?+
Build a set of next values, but only from used pages and only when next isn't -1. Then any used page id missing from that set is a head. Sort the result before returning.
Do I need to traverse the linked lists?+
No. You never follow chains. A head is defined purely by whether any used page points to it, so two linear passes over the array are enough. Walking the chains just adds code and bugs.
What edge cases should I test?+
Test an empty page whose next points to a used page, since that pointer must be ignored. Also test all pages empty (return an empty list), unsorted input, and a single used page with next of -1.
How do I prepare for this in 48 hours?+
Practice the set-of-referenced-nodes pattern: find nodes with no incoming edge. Write it once with a filter condition, then once more from memory. Spend the rest of your time on sorting and input edge cases rather than new topics.