PracHub
QuestionsCoachesLearningGuidesInterview Prep

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.

Merge a list of closed intervals into sorted, non-overlapping intervals covering the same ranges.

Constraints

  • Intervals are [start, end] pairs with start <= end.
  • Closed intervals that touch at an endpoint are considered overlapping.
  • Return intervals sorted by start for deterministic grading.

Examples

Input: ([[1,3],[2,6],[8,10],[15,18]],)

Expected Output: [[1, 6], [8, 10], [15, 18]]

Explanation: The first two intervals overlap and merge.

Input: ([[1,4],[4,5]],)

Expected Output: [[1, 5]]

Explanation: Closed intervals that touch are merged.

Input: ([[5,7],[1,2],[2,3],[10,10]],)

Expected Output: [[1, 3], [5, 7], [10, 10]]

Explanation: Input order does not matter.

Input: ([],)

Expected Output: []

Explanation: An empty interval list returns empty output.

Hints

  1. Sort by start first.
  2. Extend the previous merged interval whenever the next interval overlaps or touches it.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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
  • AI Coding 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.

Related Coding Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)