FastPrepFormat the Missing Numbers from 1 to 99
Problems/Format the Missing Numbers from 1 to 99

Format the Missing Numbers from 1 to 99

Patreon logoPatreon● EasyFULLTIMEPHONE SCREEN

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: One report gives this task: a Senior Android Engineer candidate in San Francisco who interviewed in September 2025 and did not get an offer. Their process was a recruiter screen, a phone screen with a basic algorithm question, a hiring manager talk about soft skills, an API systems round, which the candidate says is where high-level Android topics come up, and a final, harder algorithm round where the candidate says they slipped. The report lists three questions without naming a round for each; this is the first. The task: the input holds numbers in sorted order, all within 1 to 99, and the code has to show which numbers of that range are absent, in a set format that the report does not describe. We place it in the phone screen stage as an inference: it is the first question listed and matches the basic question the report gives for that screen, while the other two questions fit the API round and the final algorithm round. Our choices: the list holds whole numbers sorted from smallest to largest; 1 and 99 both belong to the range; the same number may appear more than once in the list; the function returns the text instead of printing it; the format puts absent numbers that follow one another into one block, writes a one-number block as that number and a longer block (two numbers included) as its first and last number joined by a hyphen, lists blocks from smallest to largest with a comma and a space between them, and gives empty text when nothing is absent. The limit of 1,000 list items is ours, and all three examples are ours.

An integer array nums holds values from 1 to 99 in non-decreasing order. Return a string that lists the numbers from 1 to 99 that do not appear in nums, written in the format below.

Assumption: both 1 and 99 are part of the range, and the same number may appear in nums more than once. Build the string like this:

  1. Put missing numbers that follow one another, such as 4, 5, 6, into the same block. A block ends just before a number that is in nums or after 99.
  2. Write a block with one number x as x. Write a block with two or more numbers, from a up to b, as a-b. For example, the block 4, 5 is written 4-5.
  3. Write the blocks from smallest to largest, with a comma and one space between two blocks, as in 1, 4-5, 8.
  4. When nums contains all 99 numbers, return the empty string.

Function

missingNumbers(nums: int[]) → String

Examples

Example 1

nums = [2, 3, 6, 7, 9, 10, 99]return = "1, 4-5, 8, 11-98"

The missing numbers are 1, 4, 5, 8 and every number from 11 to 98. 1 and 8 each form a block of one number. 4 and 5 follow one another, so they form the block 4-5. The last block stops at 98 because 99 is in nums.

Example 2

nums = [1, 1, 2, 50, 50, 97]return = "3-49, 51-96, 98-99"

1 and 50 each appear twice, which changes nothing: a number is either in nums or missing. The missing numbers form three blocks: 3 to 49, 51 to 96, and 98 to 99 at the end of the range.

Example 3

nums = []return = "1-99"

With an empty nums, all 99 numbers are missing, and they form a single block.

Constraints

  • 0 <= nums.length <= 1000
  • 1 <= nums[i] <= 99
  • nums is sorted in non-decreasing order.

More Patreon Phone Screen questions

  • Sliding-Window API Rate LimiterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Employee Importance from a DictionaryPHONE SCREEN · Seen Feb 2026
  • Uniform Random Number from Coin TossesPHONE SCREEN · Seen Feb 2026
  • Wordle Guess CheckerPHONE SCREEN · Seen Jan 2026
  • Org Chart Report CountsPHONE SCREEN · Seen Dec 2025
  • Pythagorean Triplets in an ArrayPHONE SCREEN · Seen Oct 2024
  • LRU Cache with TTLPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2022
  • Password GeneratorPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2022
  • Merge IntervalsPHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2022
  • JSON ParserPHONE SCREEN · Seen Jun 2021

Similar questions at other companies

  • Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
  • Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
  • Longest Common PrefixKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Single-Condition Product FilterCrowdstrike · PHONE SCREENCrowdstrike interview questions
  • Match a Variadic Function SignatureConfluent · PHONE SCREENConfluent interview questions
  • Parse and Sort Integer DataLegora · PHONE SCREEN
  • Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
  • Longest All-Present Attendance StreakOracle · PHONE SCREENOracle interview questions
  • Most Frequent NameAmazon · PHONE SCREEN
All Patreon interview questionsSee Patreon hiring insights
Saved
class Solution {
    public String missingNumbers(int[] nums) {
        // Write your code here.
    }
}
Checking account…