FastPrepFind the Four Missing Numbers in a File
Problems/Find the Four Missing Numbers in a File

Find the Four Missing Numbers in a File

Zillow logoZillow● MediumNEW GRADINTERNOAPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Asked at Zillow in 2013 and 2014. A software development intern candidate got this as the coding question of the second phone interview: a file holds every number a 32-bit machine can store except four, and the task was to work out which four are absent. A new grad candidate for a software development engineer job got the same kind of question, a file with every possible integer except four, in one of two phone interviews that were done with pen and paper and no code; the report does not say which of the two. A software engineer intern candidate was asked to find the four values missing from a file that holds a whole range of integers, and to work out how much memory the method uses; that report lists a coding test and then a phone interview of 45 minutes, and does not say which of the two had this question.

The reports do not give a memory limit, whether the numbers can be negative, the file format, the order of the numbers, or how the numbers reach the code. A file of every 32-bit number holds about 4.3 billion numbers, far too many for a practice test, so here the number of bits is an input from 3 to 16 instead of 32. The file holds every whole number from 0 up to 2 to the power bits, minus 1, with no negative numbers, except four; each number appears once, in any order. A function gets the number of bits and the numbers from the file as an array, and returns the absent numbers in increasing order. Tests check only the answer, not the memory used; the follow-up asks how much memory the method would need for 32 bits, and the editorial works this out.

Our version is about 60% the same as the reported question.

A file was meant to hold every whole number that fits in bits bits: every integer from 0 to 2^bits - 1, each exactly once. Here 2^bits means 2 to the power bits.

Four of those numbers are missing from the file. You get the numbers that are in the file as the array nums, in no particular order.

Return the four missing numbers in increasing order.

Follow-up: with bits = 32, the file holds about 4.3 billion numbers. How much memory would your method need for that file? Can you find the four numbers while keeping far less in memory than one bit for every possible number?

Function

findMissingNumbers(bits: int, nums: int[]) → int[]

Examples

Example 1

bits = 3nums = [6,1,3,4]return = [0,2,5,7]

With bits = 3, the file should hold every number from 0 to 7, which is 8 numbers. It holds 1, 3, 4 and 6, so 0, 2, 5 and 7 are missing. They are returned in increasing order.

Example 2

bits = 4nums = [12,0,7,14,2,10,5,13,1,11,6,4]return = [3,8,9,15]

With bits = 4, the numbers go from 0 to 15. In sorted order, the file holds 0, 1, 2, 4, 5, 6, 7, 10, 11, 12, 13 and 14, which is 12 numbers. The missing ones are 3, 8, 9 and 15. Two of them, 8 and 9, sit next to each other, and 15 is the largest 4-bit number.

Example 3

bits = 3nums = [3,0,2,1]return = [4,5,6,7]

The file holds 0, 1, 2 and 3, the lower half of the numbers from 0 to 7. All four missing numbers are in the upper half: 4, 5, 6 and 7.

Constraints

  • 3 <= bits <= 16
  • nums.length == 2^bits - 4
  • 0 <= nums[i] <= 2^bits - 1
  • All the numbers in nums are different.

More Zillow Phone Screen questions

  • Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
  • Build a Hash TableOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
  • Reversible Run-Length EncodingPHONE SCREEN · Seen Nov 2022
  • First Unique Character in a StringOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2022
  • Cumulative Fibonacci SumOA · PHONE SCREEN · Seen Aug 2021
  • First N Fibonacci NumbersOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2021
  • Lowest Common Ancestor in a Binary TreePHONE SCREEN · Seen Sep 2019
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2016
  • Blackjack Hand ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2016
  • FactorialPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2014

Similar questions at other companies

  • Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
  • Repeated Mirror XORMathWorks · OAMathWorks interview questions
  • SubsetsTemu · PHONE SCREENTemu interview questions
  • Calculate the Sum After Range TogglesBlink Health · OA
  • Minimize the Maximum Array ElementChubb · OAChubb interview questions
  • Minimum Cost for a Target WeightPace Stock Broking Services · PHONE SCREEN
  • Minimum Power-of-Two Removal OperationsIBM · OAIBM interview questions
  • Minimum Power-of-Two Removal OperationsVisa · OAVisa interview questions
  • Vehicle Builds for Required Terrain (Game Adaptation)Roblox · OARoblox interview questions
  • Out-of-Order TLV File ReassemblyApplied Intuition · PHONE SCREENApplied Intuition interview questions
All Zillow interview questionsSee Zillow hiring insights
Saved
class Solution {
    public int[] findMissingNumbers(int bits, int[] nums) {
        // Write your code here.
    }
}
Checking account…