Bird
Raised Fist0
Interview PrepintervalsmediumFacebookAmazonGoogle

Insert Interval

Choose your preparation mode4 modes available
🎯
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. You are given a list of intervals and a list of points. For each point, you need to find how many intervals contain it. Which algorithmic approach guarantees an optimal solution with time complexity better than O(n*m), where n is the number of intervals and m is the number of points?
easy
A. Use a line sweep algorithm by sorting interval start and end events along with points, then sweeping through them.
B. Use a brute force nested loop checking each point against every interval.
C. Use dynamic programming to precompute counts for all points in the range.
D. Sort intervals and points, then for each point use binary search to count intervals starting before and ending after the point.

Solution

  1. Step 1: Understand brute force and binary search limitations

    Brute force is O(n*m), too slow for large inputs. Binary search approach requires careful handling of interval ends and starts but is less optimal than line sweep.
  2. Step 2: Recognize line sweep advantages

    Line sweep sorts all events (starts, points, ends) and processes them in one pass, maintaining active intervals count efficiently in O((n+m) log (n+m)) time.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Line sweep processes all events sorted by coordinate with correct event ordering [OK]
Hint: Line sweep processes starts, points, ends in sorted order [OK]
Common Mistakes:
  • Assuming binary search alone is optimal
  • Thinking DP applies here
  • Using brute force for large inputs
2. Suppose the problem changes: intervals can be reused infinitely many times, and you want to count how many intervals contain each point considering unlimited reuse (e.g., intervals repeat periodically). Which modification to the line sweep approach correctly handles this scenario?
hard
A. No change needed; line sweep already counts intervals correctly regardless of reuse.
B. Preprocess intervals to merge overlapping intervals into one, then run line sweep once.
C. Use a segment tree or binary indexed tree to handle repeated intervals efficiently instead of line sweep.
D. Modify events to include multiple copies of intervals explicitly and run line sweep on expanded events.

Solution

  1. Step 1: Understand reuse impact

    Infinite reuse means intervals repeat periodically, so naive line sweep with explicit events cannot handle infinite copies.
  2. Step 2: Recognize data structure need

    Segment trees or binary indexed trees can efficiently query counts over ranges and handle repeated intervals without enumerating all copies.
  3. Step 3: Why other options fail

    No change (A) ignores infinite reuse; merging (B) loses count detail; explicit expansion (D) is infeasible for infinite repeats.
  4. Final Answer:

    Option C -> Option C
  5. Quick Check:

    Segment trees handle range queries with repeated intervals efficiently [OK]
Hint: Infinite reuse requires data structures, not event enumeration [OK]
Common Mistakes:
  • Assuming line sweep handles infinite repeats
  • Trying to expand events explicitly
  • Merging intervals loses count accuracy
3. If employees can have intervals with negative start or end times (e.g., [-5, 0]) or zero-length intervals, which modification to the sweep line algorithm is necessary to correctly find free time?
hard
A. Ignore zero-length intervals and ensure sorting places end events before start events at ties
B. Treat zero-length intervals as free time intervals
C. Sort events only by time, ignoring event type
D. Merge touching intervals as free time gaps

Solution

  1. Step 1: Handle zero-length intervals

    Zero-length intervals like [2,2] do not represent busy time and should be ignored to avoid false free intervals.
  2. Step 2: Maintain correct sorting order

    Sorting end events before start events at same time prevents reporting free time between touching intervals or zero-length intervals.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Ignoring zero-length intervals and correct sorting avoids invalid free times [OK]
Hint: Ignore zero-length intervals and sort end before start events [OK]
Common Mistakes:
  • Counting zero-length intervals as free time
  • Sorting start before end events
4. Suppose trains can arrive and depart multiple times (reusing platforms) and the schedule may include negative time values (e.g., early morning times). Which modification to the sweep line algorithm ensures correct minimum platform calculation?
hard
A. Use the same sweep line approach but ensure sorting handles negative times correctly and process events with departure before arrival on tie.
B. Use dynamic programming to handle multiple arrivals and departures per train.
C. Switch to nested loops checking overlaps since negative times break sorting assumptions.
D. Ignore negative times and treat them as zero to simplify sorting.

Solution

  1. Step 1: Recognize that negative times do not affect event sorting if handled correctly

    Sorting supports negative values naturally; no need to ignore or clamp them.
  2. Step 2: Maintain departure-before-arrival ordering on tie to avoid overcounting

    This ordering is critical regardless of time values or multiple arrivals/departures.
  3. Step 3: Continue using sweep line approach for efficiency and correctness

    Nested loops or DP are inefficient or unnecessary for this variant.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Sweep line with correct sorting handles negative and multiple events [OK]
Hint: Sorting handles negative times; keep departure before arrival on tie [OK]
Common Mistakes:
  • Ignoring negative times or clamping them
  • Switching to inefficient nested loops unnecessarily
  • Misordering events causing overcounting
5. Suppose intervals can have negative values and zero length (start == end). Which modification to the optimal solution is necessary to correctly remove covered intervals?
hard
A. Change sorting to (start ascending, end ascending) to handle zero-length intervals correctly.
B. Use strict inequality 'if end > max_end' to avoid counting zero-length intervals as uncovered.
C. Switch to brute force nested loops to handle negative and zero-length intervals safely.
D. Keep sorting by (start ascending, end descending) and use 'if end >= max_end' to include zero-length coverage cases.

Solution

  1. Step 1: Consider zero-length intervals

    Zero-length intervals (start == end) require coverage detection to include intervals with equal ends.
  2. Step 2: Adjust inequality and sorting

    Sorting by start ascending and end descending remains correct; change condition to 'if end >= max_end' to count intervals not strictly greater but equal ends.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Using >= includes zero-length coverage correctly without changing sorting [OK]
Hint: Use >= in condition to handle zero-length intervals [OK]
Common Mistakes:
  • Changing sorting breaks coverage detection
  • Using strict > misses zero-length coverage
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard