Find the Four Missing Numbers in a File
Updated
Problem statement
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 <= 16nums.length == 2^bits - 40 <= nums[i] <= 2^bits - 1- All the numbers in
numsare 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