PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates array and interval manipulation skills, algorithmic problem-solving, and the ability to reason about merging overlapping ranges in a sorted sequence.

  • Medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Insert and merge an interval

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

You are given a list of pairwise non-overlapping closed intervals [si, ei] sorted by start time, and a new interval [s, e]. Insert [s, e] into the list so that the result remains sorted and contains no overlaps (merge when necessary). Return the resulting list of intervals. Analyze time and space complexity and cover edge cases such as insertion at the beginning/end, full containment, and an empty input list.

Quick Answer: This question evaluates array and interval manipulation skills, algorithmic problem-solving, and the ability to reason about merging overlapping ranges in a sorted sequence.

Insert a new interval into sorted non-overlapping closed intervals and merge overlaps.

Constraints

  • Inputs are provided as Python literals matching the function signature.
  • Return a deterministic exact-match result.

Examples

Input: ([[1,3],[6,9]], [2,5])

Expected Output: [[1, 5], [6, 9]]

Explanation: Merge with first.

Input: ([[1,2],[3,5],[6,7],[8,10],[12,16]], [4,8])

Expected Output: [[1, 2], [3, 10], [12, 16]]

Explanation: Merge several.

Input: ([], [4,8])

Expected Output: [[4, 8]]

Explanation: Empty intervals.

Hints

  1. Choose a representation that makes the core operation simple.
  2. Handle empty and boundary inputs before the main algorithm.
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
  • 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

  • Implement Top-p (Nucleus) Sampling in NumPy - Amazon (medium)
  • Implement Multi-Head Attention from Scratch in NumPy - Amazon (medium)
  • Detect and Break a Cycle in a Singly Linked List - Amazon (medium)
  • Caesar Cipher with Translation-Table Optimization - Amazon (medium)
  • Minimum Drone Delivery Time on a Ring of Hubs - Amazon (medium)