Missing Intervals
Updated
Problem statement
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^90 <= nums.length <= 100lower <= nums[i] <= upper- All the values of
numsare unique, andnumsis 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