FastPrepInsert a Closed Interval
Problems/Insert a Closed Interval

Insert a Closed Interval

Meta logoMeta● MediumINTERNPHONE SCREEN

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The Meta ML PhD intern report links Insert Interval. Its linked statement provides sorted closed intervals, overlap rules, examples and bounds. Approximate source match: 100%.

Given sorted, non-overlapping closed intervals intervals and one closed interval newInterval, insert the new interval and merge every overlapping range. Return the result sorted by start, with no overlaps.

Two closed intervals overlap when they share any point, including an endpoint. Returning a new array is allowed; in-place modification is not required.

Function

insertInterval(intervals: int[][], newInterval: int[]) → int[][]

Examples

Example 1

intervals = [[1,3],[6,9]]newInterval = [2,5]return = [[1,5],[6,9]]

The new range overlaps the first interval only.

Example 2

intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]]newInterval = [4,8]return = [[1,2],[3,10],[12,16]]

The middle three intervals merge with the inserted range.

Example 3

intervals = []newInterval = [5,7]return = [[5,7]]

No existing interval needs merging.

Constraints

  • 0 <= intervals.length <= 10000.
  • Each interval and newInterval has exactly two integers [start,end], with 0 <= start <= end <= 100000.
  • Existing intervals are sorted by start and do not overlap.

More Meta Phone Screen questions

  • Convert a Sorted Linked List to a Balanced BSTPHONE SCREEN · Seen Nov 2026
  • Fuzzy Word Lookup With One Misspelled LetterPHONE SCREEN · Seen Nov 2026
  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
  • First Element Greater Than KPHONE SCREEN · Seen Nov 2026
  • Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
  • Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
  • Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Detonate the Maximum BombsZomato / Eternal · PHONE SCREENZomato / Eternal interview questions
  • Single Element in a Sorted ArrayGreyOrange · PHONE SCREENGreyOrange interview questions
  • Valid Triangle NumberBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
  • 2D Convolution Layer Forward PassWaymo · PHONE SCREENWaymo interview questions
  • Concurrent Discounted Card PurchasesBrex · PHONE SCREEN
  • Pairs of Songs With Total Durations Divisible by 120Cashfree Payments · PHONE SCREEN
  • Ordered IP FirewallDatabricks · PHONE SCREENDatabricks interview questions
  • Combination SumAnduril · PHONE SCREENAnduril interview questions
  • Implement QuicksortByteDance · PHONE SCREENByteDance interview questions

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Business Support Engineer Phone Screen: 1 Experience
  • Meta Software Engineer Onsite Questions: 3 Experiences
  • Meta AI Native Engineer OA and Onsite: 1 Experience
  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public int[][] insertInterval(int[][] intervals, int[] newInterval) {
        // Write your code here
    }
}
Checking account…