Loading...
You are given an array intervals, where intervals[i] = [start, end] is a time interval with start < end.
Select as many intervals as possible so that no two selected intervals overlap. Two selected intervals may touch: one may start exactly at the moment another ends.
Return the maximum number of intervals you can select.
Input: intervals = [[3,5],[4,9],[5,8]]
Output: 2
Explanation: Select [3,5] and [5,8]. The second starts exactly when the first ends, which is allowed. No selection of all three avoids overlap.
Input: intervals = [[1,2],[2,3],[3,4]]
Output: 3
Explanation: The three intervals touch end-to-end, so all of them can be selected.
intervals.length ≤2⋅105intervals[i].length =2start < end ≤109Click "Run" to test with sample cases or "Submit" to run all tests.