Check an Interval Against Existing Intervals for Conflicts

Quick Overview

Check whether one half-open candidate interval conflicts with any interval in a large unsorted collection. Respect strict start and end semantics so ranges that only touch at an endpoint do not conflict.

Check an Interval Against Existing Intervals for Conflicts

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

## Problem Given one candidate interval and a list of existing intervals, determine whether the candidate conflicts with any existing interval. All intervals use half-open semantics `[start, end)`: an interval ending at time `t` does not conflict with one starting at `t`. ### Function Contract Implement `hasIntervalConflict(candidate, intervals)` where every interval is `[start, end]` with `start < end`. ### Constraints & Assumptions - `0 <= len(intervals) <= 1,000,000`. - Endpoints are signed 64-bit integers. - Existing intervals may be unsorted and may overlap one another. - Return as soon as one conflict is found. ### Clarifying Questions to Ask - Are endpoints inclusive? Start is inclusive and end is exclusive. - Does touching at one endpoint count as conflict? No. - Are existing intervals sorted or disjoint? Neither is guaranteed. - Is input validation required? Inputs satisfy `start < end`. ```hint Negate non-overlap Two half-open intervals do not overlap when one ends at or before the other starts. The conflict predicate is the negation of that condition. ``` ### Examples ```text candidate = [4, 7] intervals = [[1, 3], [7, 9]] output = false candidate = [4, 7] intervals = [[1, 5], [8, 9]] output = true ``` ### Evaluation Focus - Uses the correct half-open overlap predicate. - Handles containment and equal-start cases without enumerating many special cases. - Avoids unnecessary sorting for a single query. - Runs in `O(n)` time and `O(1)` extra space. ### Extensions to Discuss 1. Which data structure supports many candidate queries against a fixed interval set? 2. How does the predicate change for closed intervals? 3. How would you return all conflicting interval indices?

Quick Answer: Check whether one half-open candidate interval conflicts with any interval in a large unsorted collection. Respect strict start and end semantics so ranges that only touch at an endpoint do not conflict.

|Home/Coding & Algorithms/Google
Google logo
Google
Aug 8, 2026, 12:00 AM
easySoftware EngineerTechnical ScreenCoding & Algorithms
2
0

Problem

Given one candidate interval and a list of existing intervals, determine whether the candidate conflicts with any existing interval.

All intervals use half-open semantics [start, end): an interval ending at time t does not conflict with one starting at t.

Function Contract

Implement hasIntervalConflict(candidate, intervals) where every interval is [start, end] with start < end.

Constraints & Assumptions

  • 0 <= len(intervals) <= 1,000,000 .
  • Endpoints are signed 64-bit integers.
  • Existing intervals may be unsorted and may overlap one another.
  • Return as soon as one conflict is found.

Clarifying Questions to Ask Guidance

  • Are endpoints inclusive? Start is inclusive and end is exclusive.
  • Does touching at one endpoint count as conflict? No.
  • Are existing intervals sorted or disjoint? Neither is guaranteed.
  • Is input validation required? Inputs satisfy start < end .

Examples

candidate = [4, 7]
intervals = [[1, 3], [7, 9]]
output = false

candidate = [4, 7]
intervals = [[1, 5], [8, 9]]
output = true

Evaluation Focus

  • Uses the correct half-open overlap predicate.
  • Handles containment and equal-start cases without enumerating many special cases.
  • Avoids unnecessary sorting for a single query.
  • Runs in O(n) time and O(1) extra space.

Extensions to Discuss

  1. Which data structure supports many candidate queries against a fixed interval set?
  2. How does the predicate change for closed intervals?
  3. How would you return all conflicting interval indices?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...