Merge Intervals where intervals touching at an endpoint ([1,2] and [2,3]) count as overlapping. After sorting by start, when do you merge?
Show answer
Answer
When start <= last end
Touching counts as overlap, so start equal to the last end merges. Strict less keeps [1,2] and [2,3] apart. Comparing to last start ignores ends. end <= last end only handles containment.
Source: LeetCode 56. Merge Intervals