Bird
Raised Fist0
Interview PrepintervalsmediumFacebookAmazonGoogle

Insert Interval

Choose your preparation mode4 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
🎯
Insert Interval
mediumINTERVALSFacebookAmazonGoogle

Imagine you have a calendar with booked time slots and want to add a new meeting without conflicts. How do you insert it and merge overlapping times?

💡 This problem involves managing intervals and merging overlapping ranges. Beginners often struggle because they don't visualize intervals as three distinct regions: before, overlapping, and after the new interval.
📋
Problem Statement

Given a list of non-overlapping intervals sorted by their start time, insert a new interval into the list and merge if necessary. Return the updated list of intervals sorted by start time.

1 ≤ number of intervals ≤ 10^5Intervals are sorted by start timeInterval start and end are integers in range [0, 10^9]New interval's start ≤ end
💡
Example
Input"intervals = [[1,3],[6,9]], newInterval = [2,5]"
Output[[1,5],[6,9]]

The new interval overlaps with [1,3], so they merge into [1,5]. The interval [6,9] remains unchanged.

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

The new interval overlaps with [3,5],[6,7],[8,10], merging them into [3,10].

  • Empty intervals list → output is just the new interval
  • New interval does not overlap and goes before all intervals → inserted at start
  • New interval does not overlap and goes after all intervals → inserted at end
  • New interval overlaps all intervals → merged into one big interval
⚠️
Common Mistakes
Not handling empty intervals list

Code crashes or returns incorrect output

Add check for empty intervals and return [newInterval]

Incorrectly merging intervals when boundaries just touch

Intervals that should merge remain separate or vice versa

Use <= and < carefully when comparing interval boundaries

Appending newInterval multiple times

Duplicate intervals in output

Add newInterval only once after merging overlaps

Not sorting intervals before merging in approach 2

Incorrect merges and output order

Always sort intervals by start time before merging

Modifying input intervals in place without copying

Unexpected side effects or bugs

Work on copies or document in-place modifications

🧠
Brute Force (One-Pass Merge)
💡 Starting with a brute force approach helps understand the problem deeply by explicitly checking every interval for overlap, even though it's efficient here, it builds intuition.

Intuition

Traverse intervals and add those before newInterval, merge overlapping intervals with newInterval, then add remaining intervals.

Algorithm

  1. Initialize an empty result list and index i = 0.
  2. Add all intervals that end before newInterval starts to result.
  3. Merge all intervals that overlap with newInterval by updating newInterval boundaries.
  4. Add the merged newInterval to result.
  5. Add all remaining intervals to result.
  6. Return the result list.
💡 This approach is straightforward but requires careful checks for overlaps and ordering, which can be tricky to get right initially.
</>
Code
from typing import List

def insert(intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:
    result = []
    i, n = 0, len(intervals)
    while i < n and intervals[i][1] < newInterval[0]:
        result.append(intervals[i])
        i += 1
    while i < n and intervals[i][0] <= newInterval[1]:
        newInterval[0] = min(newInterval[0], intervals[i][0])
        newInterval[1] = max(newInterval[1], intervals[i][1])
        i += 1
    result.append(newInterval)
    while i < n:
        result.append(intervals[i])
        i += 1
    return result

# Driver code
if __name__ == '__main__':
    print(insert([[1,3],[6,9]], [2,5]))  # Expected [[1,5],[6,9]]
    print(insert([[1,2],[3,5],[6,7],[8,10],[12,16]], [4,8]))  # Expected [[1,2],[3,10],[12,16]]
Line Notes
result = []Initialize the output list to store merged intervals
while i < n and intervals[i][1] < newInterval[0]Add all intervals that end before newInterval starts, no overlap possible
while i < n and intervals[i][0] <= newInterval[1]Merge all intervals that overlap with newInterval
newInterval[0] = min(newInterval[0], intervals[i][0])Update start of merged interval to earliest start
newInterval[1] = max(newInterval[1], intervals[i][1])Update end of merged interval to latest end
result.append(newInterval)Add the merged interval after processing overlaps
while i < nAdd all remaining intervals after newInterval
return resultReturn the final merged list
import java.util.*;

public class InsertInterval {
    public static int[][] insert(int[][] intervals, int[] newInterval) {
        List<int[]> result = new ArrayList<>();
        int i = 0, n = intervals.length;
        while (i < n && intervals[i][1] < newInterval[0]) {
            result.add(intervals[i]);
            i++;
        }
        while (i < n && intervals[i][0] <= newInterval[1]) {
            newInterval[0] = Math.min(newInterval[0], intervals[i][0]);
            newInterval[1] = Math.max(newInterval[1], intervals[i][1]);
            i++;
        }
        result.add(newInterval);
        while (i < n) {
            result.add(intervals[i]);
            i++;
        }
        return result.toArray(new int[result.size()][]);
    }

    public static void main(String[] args) {
        int[][] res1 = insert(new int[][]{{1,3},{6,9}}, new int[]{2,5});
        System.out.println(Arrays.deepToString(res1)); // [[1,5],[6,9]]
        int[][] res2 = insert(new int[][]{{1,2},{3,5},{6,7},{8,10},{12,16}}, new int[]{4,8});
        System.out.println(Arrays.deepToString(res2)); // [[1,2],[3,10],[12,16]]
    }
}
Line Notes
List<int[]> result = new ArrayList<>();Create a dynamic list to store merged intervals
while (i < n && intervals[i][1] < newInterval[0])Add intervals that end before newInterval starts, no overlap
while (i < n && intervals[i][0] <= newInterval[1])Merge overlapping intervals by updating newInterval boundaries
newInterval[0] = Math.min(newInterval[0], intervals[i][0]);Update start of merged interval
newInterval[1] = Math.max(newInterval[1], intervals[i][1]);Update end of merged interval
result.add(newInterval);Add the merged interval after processing overlaps
while (i < n)Add remaining intervals after newInterval
return result.toArray(new int[result.size()][]);Convert list back to array for output
#include <iostream>
#include <vector>
using namespace std;

vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {
    vector<vector<int>> result;
    int i = 0, n = intervals.size();
    while (i < n && intervals[i][1] < newInterval[0]) {
        result.push_back(intervals[i]);
        i++;
    }
    while (i < n && intervals[i][0] <= newInterval[1]) {
        newInterval[0] = min(newInterval[0], intervals[i][0]);
        newInterval[1] = max(newInterval[1], intervals[i][1]);
        i++;
    }
    result.push_back(newInterval);
    while (i < n) {
        result.push_back(intervals[i]);
        i++;
    }
    return result;
}

int main() {
    vector<vector<int>> intervals1 = {{1,3},{6,9}};
    vector<int> newInterval1 = {2,5};
    vector<vector<int>> res1 = insert(intervals1, newInterval1);
    for (auto &iv : res1) cout << '[' << iv[0] << ',' << iv[1] << "] ";
    cout << endl; // Expected [1,5] [6,9]

    vector<vector<int>> intervals2 = {{1,2},{3,5},{6,7},{8,10},{12,16}};
    vector<int> newInterval2 = {4,8};
    vector<vector<int>> res2 = insert(intervals2, newInterval2);
    for (auto &iv : res2) cout << '[' << iv[0] << ',' << iv[1] << "] ";
    cout << endl; // Expected [1,2] [3,10] [12,16]
    return 0;
}
Line Notes
vector<vector<int>> result;Initialize vector to store merged intervals
while (i < n && intervals[i][1] < newInterval[0])Add intervals that end before newInterval starts
while (i < n && intervals[i][0] <= newInterval[1])Merge overlapping intervals by updating newInterval
newInterval[0] = min(newInterval[0], intervals[i][0]);Update start boundary of merged interval
newInterval[1] = max(newInterval[1], intervals[i][1]);Update end boundary of merged interval
result.push_back(newInterval);Add merged interval after merging overlaps
while (i < n)Add remaining intervals after newInterval
return result;Return the final merged intervals
function insert(intervals, newInterval) {
    const result = [];
    let i = 0, n = intervals.length;
    while (i < n && intervals[i][1] < newInterval[0]) {
        result.push(intervals[i]);
        i++;
    }
    while (i < n && intervals[i][0] <= newInterval[1]) {
        newInterval[0] = Math.min(newInterval[0], intervals[i][0]);
        newInterval[1] = Math.max(newInterval[1], intervals[i][1]);
        i++;
    }
    result.push(newInterval);
    while (i < n) {
        result.push(intervals[i]);
        i++;
    }
    return result;
}

console.log(insert([[1,3],[6,9]], [2,5])); // [[1,5],[6,9]]
console.log(insert([[1,2],[3,5],[6,7],[8,10],[12,16]], [4,8])); // [[1,2],[3,10],[12,16]]
Line Notes
const result = [];Initialize array to hold merged intervals
while (i < n && intervals[i][1] < newInterval[0])Add intervals before newInterval without overlap
while (i < n && intervals[i][0] <= newInterval[1])Merge overlapping intervals with newInterval
newInterval[0] = Math.min(newInterval[0], intervals[i][0]);Update start of merged interval
newInterval[1] = Math.max(newInterval[1], intervals[i][1]);Update end of merged interval
result.push(newInterval);Add merged newInterval after merging
while (i < n)Add intervals after newInterval
return result;Return final merged intervals
Complexity
TimeO(n)
SpaceO(n)

We iterate through the intervals once, merging overlaps as we go. The output list can be up to size n+1 in worst case.

💡 For n=10,000 intervals, this means about 10,000 comparisons and merges, which is efficient enough for interviews.
Interview Verdict: Accepted

This approach is efficient and accepted in interviews, demonstrating a solid understanding of interval merging.

🧠
Sorting + Merge After Insertion
💡 This approach inserts the new interval at the end and then sorts and merges all intervals. It is simpler to implement but less efficient.

Intuition

Add the new interval to the list, sort all intervals by start time, then merge overlapping intervals in one pass.

Algorithm

  1. Append the new interval to the intervals list.
  2. Sort the intervals by their start time.
  3. Initialize a result list with the first interval.
  4. Iterate through the sorted intervals and merge overlapping intervals.
  5. Return the merged intervals.
💡 This approach is easier to implement but sorting adds extra time complexity, which might be acceptable depending on constraints.
</>
Code
from typing import List

def insert(intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:
    intervals.append(newInterval)
    intervals.sort(key=lambda x: x[0])
    merged = [intervals[0]]
    for i in range(1, len(intervals)):
        if intervals[i][0] <= merged[-1][1]:
            merged[-1][1] = max(merged[-1][1], intervals[i][1])
        else:
            merged.append(intervals[i])
    return merged

# Driver code
if __name__ == '__main__':
    print(insert([[1,3],[6,9]], [2,5]))  # Expected [[1,5],[6,9]]
    print(insert([[1,2],[3,5],[6,7],[8,10],[12,16]], [4,8]))  # Expected [[1,2],[3,10],[12,16]]
Line Notes
intervals.append(newInterval)Add the new interval to the list before sorting
intervals.sort(key=lambda x: x[0])Sort intervals by start time to prepare for merging
merged = [intervals[0]]Initialize merged list with first interval
if intervals[i][0] <= merged[-1][1]Check if current interval overlaps with last merged interval
merged[-1][1] = max(merged[-1][1], intervals[i][1])Merge intervals by updating end time
else: merged.append(intervals[i])No overlap, add current interval to merged list
return mergedReturn the merged intervals
import java.util.*;

public class InsertInterval {
    public static int[][] insert(int[][] intervals, int[] newInterval) {
        int n = intervals.length;
        int[][] allIntervals = new int[n + 1][];
        System.arraycopy(intervals, 0, allIntervals, 0, n);
        allIntervals[n] = newInterval;
        Arrays.sort(allIntervals, Comparator.comparingInt(a -> a[0]));
        List<int[]> merged = new ArrayList<>();
        merged.add(allIntervals[0]);
        for (int i = 1; i < allIntervals.length; i++) {
            int[] last = merged.get(merged.size() - 1);
            if (allIntervals[i][0] <= last[1]) {
                last[1] = Math.max(last[1], allIntervals[i][1]);
            } else {
                merged.add(allIntervals[i]);
            }
        }
        return merged.toArray(new int[merged.size()][]);
    }

    public static void main(String[] args) {
        int[][] res1 = insert(new int[][]{{1,3},{6,9}}, new int[]{2,5});
        System.out.println(Arrays.deepToString(res1)); // [[1,5],[6,9]]
        int[][] res2 = insert(new int[][]{{1,2},{3,5},{6,7},{8,10},{12,16}}, new int[]{4,8});
        System.out.println(Arrays.deepToString(res2)); // [[1,2],[3,10],[12,16]]
    }
}
Line Notes
int[][] allIntervals = new int[n + 1][];Create new array to hold original plus new interval
System.arraycopy(intervals, 0, allIntervals, 0, n);Copy original intervals into new array
allIntervals[n] = newInterval;Add new interval at the end
Arrays.sort(allIntervals, Comparator.comparingInt(a -> a[0]));Sort all intervals by start time
List<int[]> merged = new ArrayList<>();Initialize list to hold merged intervals
if (allIntervals[i][0] <= last[1])Check overlap with last merged interval
last[1] = Math.max(last[1], allIntervals[i][1]);Merge intervals by updating end time
merged.add(allIntervals[i]);Add non-overlapping interval
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {
    intervals.push_back(newInterval);
    sort(intervals.begin(), intervals.end(), [](const vector<int>& a, const vector<int>& b) {
        return a[0] < b[0];
    });
    vector<vector<int>> merged;
    merged.push_back(intervals[0]);
    for (int i = 1; i < intervals.size(); i++) {
        if (intervals[i][0] <= merged.back()[1]) {
            merged.back()[1] = max(merged.back()[1], intervals[i][1]);
        } else {
            merged.push_back(intervals[i]);
        }
    }
    return merged;
}

int main() {
    vector<vector<int>> intervals1 = {{1,3},{6,9}};
    vector<int> newInterval1 = {2,5};
    vector<vector<int>> res1 = insert(intervals1, newInterval1);
    for (auto &iv : res1) cout << '[' << iv[0] << ',' << iv[1] << "] ";
    cout << endl; // Expected [1,5] [6,9]

    vector<vector<int>> intervals2 = {{1,2},{3,5},{6,7},{8,10},{12,16}};
    vector<int> newInterval2 = {4,8};
    vector<vector<int>> res2 = insert(intervals2, newInterval2);
    for (auto &iv : res2) cout << '[' << iv[0] << ',' << iv[1] << "] ";
    cout << endl; // Expected [1,2] [3,10] [12,16]
    return 0;
}
Line Notes
intervals.push_back(newInterval);Add new interval to the list
sort(intervals.begin(), intervals.end(), ...Sort intervals by start time
vector<vector<int>> merged;Initialize vector to hold merged intervals
merged.push_back(intervals[0]);Start merged list with first interval
if (intervals[i][0] <= merged.back()[1])Check if current interval overlaps with last merged
merged.back()[1] = max(merged.back()[1], intervals[i][1]);Merge intervals by updating end time
merged.push_back(intervals[i]);Add non-overlapping interval
function insert(intervals, newInterval) {
    intervals.push(newInterval);
    intervals.sort((a, b) => a[0] - b[0]);
    const merged = [intervals[0]];
    for (let i = 1; i < intervals.length; i++) {
        if (intervals[i][0] <= merged[merged.length - 1][1]) {
            merged[merged.length - 1][1] = Math.max(merged[merged.length - 1][1], intervals[i][1]);
        } else {
            merged.push(intervals[i]);
        }
    }
    return merged;
}

console.log(insert([[1,3],[6,9]], [2,5])); // [[1,5],[6,9]]
console.log(insert([[1,2],[3,5],[6,7],[8,10],[12,16]], [4,8])); // [[1,2],[3,10],[12,16]]
Line Notes
intervals.push(newInterval);Add new interval to intervals array
intervals.sort((a, b) => a[0] - b[0]);Sort intervals by start time
const merged = [intervals[0]];Initialize merged array with first interval
if (intervals[i][0] <= merged[merged.length - 1][1])Check overlap with last merged interval
merged[merged.length - 1][1] = Math.max(...)Merge intervals by updating end time
merged.push(intervals[i]);Add non-overlapping interval
Complexity
TimeO(n log n)
SpaceO(n)

Sorting the intervals dominates the time complexity. Merging afterwards is O(n).

💡 For n=10,000, sorting takes about 10,000 * log2(10,000) ≈ 132,877 operations, slower than linear.
Interview Verdict: Accepted but less optimal

This approach works but is less efficient due to sorting. Good for quick implementation if constraints allow.

📊
All Approaches - One-Glance Tradeoffs
💡 The optimal one-pass approach is best for interviews. The sorting approach is simpler but slower. Brute force is mainly for understanding.
ApproachTimeSpaceStack RiskReconstructUse In Interview
1. Brute Force (One-Pass Merge)O(n)O(n)NoN/ACode this approach for best balance of clarity and efficiency
2. Sorting + MergeO(n log n)O(n)NoN/AMention as simpler alternative; code if time permits
💼
Interview Strategy
💡 Use this guide to understand the problem deeply, practice coding the optimal approach, and prepare for common interview questions and edge cases.

How to Present

Step 1: Clarify input format and constraints with the interviewer.Step 2: Describe the brute force approach to show understanding of the problem.Step 3: Discuss the sorting + merge approach as a simpler alternative.Step 4: Present the optimal one-pass approach with three regions.Step 5: Code the optimal approach carefully, explaining each step.Step 6: Test with edge cases and discuss time/space complexity.

Time Allocation

Clarify: 2min → Approach: 5min → Code: 10min → Test: 3min. Total ~20min

What the Interviewer Tests

The interviewer tests your ability to handle interval merging, edge cases, and write clean, efficient code.

Common Follow-ups

  • What if intervals are not sorted? → Sort first or use a data structure.
  • How to handle intervals with open or closed boundaries? → Clarify and adjust comparisons.
  • Can you do this in-place? → Yes, but careful with shifting elements.
  • How to insert multiple intervals? → Repeat insertion or merge all at once.
💡 These follow-ups test your flexibility and deeper understanding of interval problems.
🔍
Pattern Recognition

When to Use

1) Input is a list of intervals, 2) Need to insert or merge intervals, 3) Intervals sorted or unsorted, 4) Output requires merged intervals

Signature Phrases

insert a new intervalmerge overlapping intervalsnon-overlapping intervals sorted by start time

NOT This Pattern When

Problems involving interval scheduling optimization or DP on intervals are different patterns.

Similar Problems

Merge Intervals - merges all overlapping intervals in a listNon-overlapping Intervals - remove minimum intervals to avoid overlapMeeting Rooms - check if a person can attend all meetings

Practice

(1/5)
1. Consider the following Python code that determines if a person can attend all meetings given a list of intervals. What is the return value when the input is [[7,10],[2,4]]?
from typing import List

def can_attend_meetings(intervals: List[List[int]]) -> bool:
    intervals.sort(key=lambda x: x[0])
    end = float('-inf')
    for interval in intervals:
        if interval[0] < end:
            return False
        end = interval[1]
    return True

print(can_attend_meetings([[7,10],[2,4]]))
easy
A. None
B. False
C. Raises an exception
D. True

Solution

  1. Step 1: Sort intervals by start time

    Input [[7,10],[2,4]] becomes [[2,4],[7,10]].
  2. Step 2: Iterate and check overlaps

    Initialize end = -inf. First interval start=2 > -inf, update end=4. Second interval start=7 > 4, update end=10. No overlaps found, return True.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Intervals sorted and no overlaps detected [OK]
Hint: Sort then check if current start < previous end [OK]
Common Mistakes:
  • Confusing return value due to unsorted intervals
2. You are given a list of time intervals representing booked meeting rooms. Your task is to combine all overlapping intervals into the minimum number of non-overlapping intervals. Which algorithmic approach guarantees an optimal and efficient solution for this problem?
easy
A. Use a greedy approach that always merges the earliest starting interval with the next one without sorting.
B. Sort intervals by start time and then merge overlapping intervals in a single pass.
C. Use dynamic programming to find the maximum number of non-overlapping intervals and then merge accordingly.
D. Check every pair of intervals with nested loops to merge overlaps until no overlaps remain.

Solution

  1. Step 1: Understand the problem requires merging overlapping intervals efficiently.

    Sorting intervals by their start time ensures that overlapping intervals are adjacent, enabling a single pass merge.
  2. Step 2: Evaluate each option's approach.

    Use a greedy approach that always merges the earliest starting interval with the next one without sorting. fails because without sorting, intervals may be merged incorrectly or missed. Use dynamic programming to find the maximum number of non-overlapping intervals and then merge accordingly. is unrelated as DP is not needed here. Check every pair of intervals with nested loops to merge overlaps until no overlaps remain. is brute force with O(n²) time, inefficient for large inputs. Sort intervals by start time and then merge overlapping intervals in a single pass. correctly sorts and merges in O(n log n) time.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Sorting + one pass merge is the classic optimal pattern for merging intervals. [OK]
Hint: Sort intervals first, then merge in one pass [OK]
Common Mistakes:
  • Trying to merge without sorting
  • Using nested loops leading to O(n²) time
3. Examine the following code snippet intended to compute the minimum number of platforms required. Identify the line containing the subtle bug that can cause incorrect platform count when a train departs and another arrives at the same time.
medium
A. Line 6: Appending departure events with -1 instead of 1
B. Line 10: Not resetting platforms_needed before loop
C. Line 8: Sorting events with arrival before departure on tie
D. Line 12: Not updating max_platforms after each event

Solution

  1. Step 1: Understand event sorting importance

    When arrival and departure times are equal, departures must be processed before arrivals to free platforms.
  2. Step 2: Identify sorting key bug

    The code sorts with arrival (1) before departure (-1) on tie, causing overcounting platforms.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Departure before arrival on tie avoids overcounting [OK]
Hint: Departure events must come before arrival on tie [OK]
Common Mistakes:
  • Sorting arrival before departure on tie
  • Forgetting to update max_platforms
  • Incorrect event type values
4. Suppose the meeting intervals can be reused multiple times (i.e., a meeting can be attended multiple times if no overlaps occur). Which modification to the algorithm is necessary to correctly determine if a person can attend all meetings without overlap?
hard
A. Sort intervals by end time and greedily select intervals to maximize non-overlapping meetings.
B. No change needed; the original algorithm already handles reuse correctly.
C. Use a frequency map to count how many times each interval appears and check overlaps accordingly.
D. Sort intervals by start time and check overlaps as before, but also track counts of repeated intervals.

Solution

  1. Step 1: Understand reuse scenario

    Reusing intervals means attending multiple instances of the same meeting, so we want to maximize the number of non-overlapping meetings.
  2. Step 2: Identify correct approach

    Sorting by end time and greedily selecting earliest finishing meetings maximizes non-overlapping intervals, handling reuse correctly.
  3. Step 3: Why other options fail

    Original algorithm only checks if all intervals can be attended once; frequency maps or tracking counts do not solve scheduling conflicts optimally.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Greedy by end time is classic interval scheduling for maximum non-overlapping intervals [OK]
Hint: Reuse requires interval scheduling by end time [OK]
Common Mistakes:
  • Assuming original overlap check suffices for reuse
  • Trying to track counts without scheduling logic
5. Suppose balloons can be reused multiple times after bursting (i.e., an arrow can burst a balloon multiple times if shot at different points). How does this affect the algorithm to find the minimum number of arrows needed?
hard
A. The original greedy algorithm still applies without changes.
B. We must use dynamic programming to track multiple bursts per balloon.
C. The problem reduces to counting unique balloons since reuse removes overlap constraints.
D. We can shoot arrows only at balloon start points to minimize arrows.

Solution

  1. Step 1: Understand reuse effect

    If balloons can be burst multiple times independently, overlapping intervals no longer reduce arrow count.
  2. Step 2: Simplify problem

    Each balloon requires at least one arrow, so minimum arrows equal number of unique balloons.
  3. Step 3: Algorithm implication

    Overlap and interval sorting become irrelevant; counting balloons suffices.
  4. Final Answer:

    Option C -> Option C
  5. Quick Check:

    Reuse breaks overlap optimization, so count balloons directly [OK]
Hint: Reuse removes overlap benefit; count balloons directly [OK]
Common Mistakes:
  • Assuming greedy still works unchanged
  • Trying to track multiple bursts with DP unnecessarily
  • Ignoring that reuse breaks interval overlap logic