PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Meta

Merge overlapping intervals

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of interval operations, array manipulation, and algorithmic efficiency, along with correct handling of edge cases and large-scale inputs.

  • medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Merge overlapping intervals

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given a list of closed intervals on the number line, where each interval is represented as a pair of integers `[start, end]` with `start <= end`. Write a function that merges all overlapping intervals and returns a new list of non-overlapping intervals that cover exactly the same ranges as the input. The output list can be returned in any order, but within each interval the first element must be the start and the second element must be the end. **Example:** - Input: `[[1,3], [2,6], [8,10], [15,18]]` - Output: `[[1,6], [8,10], [15,18]]` - Explanation: Intervals `[1,3]` and `[2,6]` overlap and are merged into `[1,6]`. The other intervals do not overlap with any others. **Another example:** - Input: `[[1,4], [4,5]]` - Output: `[[1,5]]` **Constraints:** - `1 <= n <= 10^5` where `n` is the number of intervals - Interval endpoints are integers in the range `[-10^9, 10^9]`

Quick Answer: This question evaluates understanding of interval operations, array manipulation, and algorithmic efficiency, along with correct handling of edge cases and large-scale inputs.

Related Interview Questions

  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve a Key-Door Corridor Maze - Meta (medium)
  • Solve Array Merge and Parentheses Cleanup - Meta (medium)
  • Solve Two Backtracking Array Problems - Meta (hard)
  • Solve Maze and Suffix Problems - Meta (medium)
Meta logo
Meta
Dec 8, 2025, 6:32 PM
Software Engineer
Onsite
Coding & Algorithms
3
0

You are given a list of closed intervals on the number line, where each interval is represented as a pair of integers [start, end] with start <= end.

Write a function that merges all overlapping intervals and returns a new list of non-overlapping intervals that cover exactly the same ranges as the input.

The output list can be returned in any order, but within each interval the first element must be the start and the second element must be the end.

Example:

  • Input: [[1,3], [2,6], [8,10], [15,18]]
  • Output: [[1,6], [8,10], [15,18]]
    • Explanation: Intervals [1,3] and [2,6] overlap and are merged into [1,6] . The other intervals do not overlap with any others.

Another example:

  • Input: [[1,4], [4,5]]
  • Output: [[1,5]]

Constraints:

  • 1 <= n <= 10^5 where n is the number of intervals
  • Interval endpoints are integers in the range [-10^9, 10^9]

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Software Engineer•Meta Software Engineer•Meta Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.