← IBM Interview Insights

IBM·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

IBM software engineer coding round with one algorithmic problem about merging time intervals. Pretty standard stuff but there were some subtle edge cases worth thinking through.

Questions Asked (1)

Q1

Given n intervals where each interval [start, end] is inclusive on both ends, compute the total amount of time during which at least one process is running.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

First thing I fumbled was the inclusive endpoint part.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem and edge cases, then propose an efficient algorithm such as sorting intervals by start time and merging overlapping intervals while tracking total covered length. Discuss time and space complexity, and consider trade-offs between sorting-based and sweep-line approaches.

Pro tip: Explicitly handle the inclusive endpoints by treating intervals as half-open [start, end+1) or by carefully merging when next.start <= current.end. Mentioning this detail shows attention to problem constraints and prevents off-by-one errors.

1. Clarify requirements and edge cases

Ask about input size, whether intervals can be unsorted, if endpoints are integers, and if zero-length intervals are possible. Confirm that overlapping intervals should be merged and that total time is the union length.

2. Choose an algorithm

Propose sorting intervals by start time, then iterating to merge overlaps. Alternatively, mention a sweep-line approach using events (start +1, end+1 -1) if the problem scale or constraints favor it.

3. Walk through the merge logic

Explain how to maintain a current merged interval and accumulate total time when a non-overlapping interval is found. Emphasize the inclusive endpoint condition: merge if next.start <= current.end.

4. Analyze complexity and trade-offs

State that sorting takes O(n log n) time and O(1) or O(n) extra space depending on implementation. Compare with sweep-line which may be O(n log n) due to sorting events but can handle streaming data.

5. Test with examples

Validate the approach with simple cases (single interval, disjoint intervals, fully overlapping, touching intervals) and a complex case to ensure correctness.

Key Points to Mention

  • Sorting intervals by start time to enable linear merge
  • Merging condition: next.start <= current.end (inclusive)
  • Accumulating total time only for non-overlapping segments
  • Time complexity O(n log n) due to sorting, space O(1) if in-place
  • Alternative sweep-line approach with events for streaming or large n
  • Handling edge cases: empty input, zero-length intervals, unsorted input

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.