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.
Examples
Example 1
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.
Example 2
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.
Constraints
1≤intervals.length≤2⋅105
intervals[i].length=2
1≤start<end≤109
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up