PracHub
QuestionsLearningGuidesInterview Prep
|Home/Coding & Algorithms/Bytedance

Merge Overlapping Intervals

Last updated: Jul 28, 2026

Quick Overview

Merge an unsorted collection of closed integer intervals into a deterministic, non-overlapping union. Explain shared-endpoint behavior, duplicates, containment, empty input, immutability, complexity, and how the contract changes for half-open or streaming intervals.

  • easy
  • Bytedance
  • Coding & Algorithms
  • Software Engineer

Merge Overlapping Intervals

Company: Bytedance

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

# Merge Overlapping Intervals Implement `merge_intervals(intervals)` for a list of closed integer intervals. Each interval is `[start, end]` with `start <= end`. Return the union as non-overlapping intervals sorted by increasing start. Two intervals overlap when they share at least one point. Because the intervals are closed, `[1, 4]` and `[4, 6]` must merge into `[1, 6]`. The input may be unsorted and may contain duplicates or intervals fully contained in other intervals. Do not mutate the caller's list. ## Constraints - `0 <= len(intervals) <= 100000` - `-10^9 <= start <= end <= 10^9` - The output must be deterministic and contain no mergeable adjacent pair. ## Examples - `[[1, 3], [2, 6], [8, 10], [15, 18]]` returns `[[1, 6], [8, 10], [15, 18]]`. - `[[4, 6], [1, 4], [2, 3]]` returns `[[1, 6]]`. - `[]` returns `[]`. ## Clarifications Explain the ordering invariant your implementation relies on, why a single comparison is sufficient after that invariant is established, and the time and auxiliary-space costs. ## Hints Look for an ordering that makes every possible merge partner local rather than requiring all-pairs comparisons. ## Extensions - How would the rule change for half-open intervals `[start, end)`? - How would you merge an incoming interval into an already sorted, non-overlapping list? - What would you change if the input were too large to fit in memory?

Quick Answer: Merge an unsorted collection of closed integer intervals into a deterministic, non-overlapping union. Explain shared-endpoint behavior, duplicates, containment, empty input, immutability, complexity, and how the contract changes for half-open or streaming intervals.

Related Interview Questions

  • Remove Duplicate Letters Lexicographically - Bytedance (medium)
  • Elements Occurring More Than n/3 Times in a Sorted Array - Bytedance (medium)
  • Least Frequently Used (LFU) Cache - Bytedance (hard)
  • Course Schedule Feasibility - Bytedance (hard)
|Home/Coding & Algorithms/Bytedance

Merge Overlapping Intervals

Bytedance logo
Bytedance
Jul 22, 2026, 12:00 AM
easySoftware EngineerTechnical ScreenCoding & Algorithms
0
0

Merge Overlapping Intervals

Implement merge_intervals(intervals) for a list of closed integer intervals. Each interval is [start, end] with start <= end. Return the union as non-overlapping intervals sorted by increasing start.

Two intervals overlap when they share at least one point. Because the intervals are closed, [1, 4] and [4, 6] must merge into [1, 6]. The input may be unsorted and may contain duplicates or intervals fully contained in other intervals. Do not mutate the caller's list.

Constraints

  • 0 <= len(intervals) <= 100000
  • -10^9 <= start <= end <= 10^9
  • The output must be deterministic and contain no mergeable adjacent pair.

Examples

  • [[1, 3], [2, 6], [8, 10], [15, 18]] returns [[1, 6], [8, 10], [15, 18]] .
  • [[4, 6], [1, 4], [2, 3]] returns [[1, 6]] .
  • [] returns [] .

Clarifications

Explain the ordering invariant your implementation relies on, why a single comparison is sufficient after that invariant is established, and the time and auxiliary-space costs.

Hints

Look for an ordering that makes every possible merge partner local rather than requiring all-pairs comparisons.

Extensions

  • How would the rule change for half-open intervals [start, end) ?
  • How would you merge an incoming interval into an already sorted, non-overlapping list?
  • What would you change if the input were too large to fit in memory?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

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

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

Product

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

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.