Optimal Interval Difference

Problem Overview

  • Given an array of intervals [start, end], find the minimum gap between consecutive intervals after consolidating overlaps.
  • Input: N followed by N pairs of integers (start, end). Output: a single integer, the smallest difference start(current) - end(previous) among the merged, sorted intervals.
  • Context: useful for scheduling or timeline analysis where you need the tightest gap between events.
  • This Amazon interviews problem is a common coding interview interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: