← IBM Interview Insights

IBM·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

IBM coding round for a Software Engineer role. One algorithm question on interval merging, fairly standard stuff but the edge cases around inclusive endpoints tripped me up a bit.

Questions Asked (1)

Q1

Given n intervals represented as [start, end] (inclusive on both ends), each corresponding to a running process, compute the total time during which at least one process is running.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I jumped straight into sort-and-merge without asking about the endpoints first, which came back to bite me when they asked me to verify my calculation.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify that intervals are inclusive and may overlap. Then, sort intervals by start time and merge overlapping intervals, summing the lengths of merged intervals to get total running time. Alternatively, use a sweep line with events to count active processes.

Pro tip: Mention that sorting is O(n log n) and that the merge approach is optimal; also note that if intervals are already sorted, a single pass suffices. This shows awareness of input assumptions and efficiency.

1. Clarify requirements and edge cases

Confirm that intervals are inclusive, may overlap, and that we need total time with at least one process running. Discuss edge cases like empty input, single interval, and touching intervals (e.g., [1,2] and [2,3] overlap at point 2).

2. Choose an approach

Decide between sorting and merging intervals or using a sweep line with events. Both are valid; sorting is simpler and O(n log n). Explain the trade-offs.

3. Implement the algorithm

For sorting: sort by start, then iterate, merging overlapping intervals and accumulating lengths. For sweep line: create events (start +1, end -1), sort, and track active count to sum durations where count > 0.

4. Analyze complexity and test

State time complexity O(n log n) due to sorting, space O(n) for sorting or O(1) extra if in-place. Walk through a small example to verify correctness.

Key Points to Mention

  • Inclusive intervals: merging condition is next.start <= current.end (not <).
  • Sorting by start time is key for the merge approach.
  • Sweep line alternative: events sorted by time, handle end before start if intervals are inclusive to avoid double-counting at endpoints.
  • Time complexity O(n log n) and space complexity O(n) or O(1) depending on implementation.
  • Edge cases: empty input, single interval, intervals that just touch.
  • Trade-offs: sorting is simpler; sweep line can be more efficient if events are already sorted or if we need to handle dynamic updates.

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