FastPrepMissing Intervals
Problems/Missing Intervals

Missing Intervals

IBM logoIBM● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IBM new grad online assessment for the Associate System Engineer role, during a campus hiring drive. It was one of two coding questions. The task was to find which numbers are absent from a range and group them into runs.

The report only names the topic. It gives no input format, examples or limits. Here, you get a sorted list of unique numbers inside a range from lower to upper, and you return each run of absent numbers as a [start, end] pair. We chose up to 100 numbers and bounds from -10^9 to 10^9.

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

You are given two integers lower and upper, and a sorted array nums of unique integers. Every value in nums is between lower and upper, inclusive.

A number x is missing when lower <= x <= upper and x is not in nums.

Group the missing numbers into runs of consecutive integers, and make each run as long as possible. Write each run as a pair [start, end]: it holds every integer from start to end, including both ends. A run with a single missing number x is written as [x, x].

Return the list of runs sorted from smallest to largest. If no number is missing, return an empty list.

Function

findMissingRanges(nums: int[], lower: int, upper: int) → List<List<Integer>>

Examples

Example 1

nums = [2,3,7,9]lower = 0upper = 12return = [[0,1],[4,6],[8,8],[10,12]]

The numbers from 0 to 12 that are not in nums are 0, 1, 4, 5, 6, 8, 10, 11, 12. They form four runs: 0 to 1, 4 to 6, 8 alone, and 10 to 12.

Example 2

nums = []lower = -3upper = 3return = [[-3,3]]

nums is empty, so every number from -3 to 3 is missing. They form one run, [-3, 3].

Example 3

nums = [4,5,6]lower = 4upper = 6return = []

Every number from 4 to 6 is in nums, so nothing is missing and the answer is an empty list.

Constraints

  • -10^9 <= lower <= upper <= 10^9
  • 0 <= nums.length <= 100
  • lower <= nums[i] <= upper
  • All the values of nums are unique, and nums is sorted in increasing order.

More IBM Online Assessment questions

  • Count Peaks and ValleysOA · Seen Nov 2026
  • Last Object Exit TimeOA · Seen Nov 2026
  • Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
  • Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
  • Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
  • Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
  • Tree Pythagorean TriplesOA · Seen Oct 2026
  • Minimum Power-of-Two Removal OperationsOA · Seen Oct 2026
  • Maximum Compatible Time WindowsOA · Seen Oct 2026
  • Query Type Frequency WindowOA · Seen Oct 2026

Similar questions at other companies

  • Total Cost Against the Lowest Earlier PricePayPal · OAPayPal interview questions
  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Count Valid Square PairsAuxoAI · OA
  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Two SumAmazon · OA · PHONE SCREEN
  • Find Words That Can Be Formed by CharactersTabaPay · OA
  • Server InvestmentRippling · OARippling interview questions
  • Book Reading EveningsGoogle · OAGoogle interview questions
  • Minimum Index Distance Between Person and CakeSnowflake · OA · PHONE SCREENSnowflake interview questions
  • Basic Item DiscountsPalantir · OAPalantir interview questions

IBM interview experiences

  • IBM Full-Time SWE OA Questions: 1 Experience
  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public List<List<Integer>> findMissingRanges(int[] nums, int lower, int upper) {
        // Write your code here.
    }
}
Checking account…