FastPrepRecover Corrupted Master Page
Problems/Recover Corrupted Master Page

Recover Corrupted Master Page

Microsoft logoMicrosoftFULLTIMEONSITE INTERVIEW

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

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.

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int[] recoverMasterPage(int[][] pages) {
      // write your code here
    }
}
Checking account…