Given an array of intervals `intervals` where `intervals[i] = [start_i, end_i]`, return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.
Note that intervals which touch at a point like `[1, 2]` and `[2, 3]` are considered non-overlapping.
### Constraints
- `1 <= intervals.length <= 10^5`
- `intervals[i].length == 2`
- `-5 * 10^4 <= start_i < end_i <= 5 * 10^4`
### Input Format
- Line 1: An integer `n` representing the number of intervals.
- The next `n` lines: Two space-separated integers `start end`.
### Output Format
Print the minimum number of intervals to remove.
Sample Cases
Example 1Sample Case
Input: 4
1 2
2 3
3 4
1 3
Output: 1
Example 2Sample Case
Input: 3
1 2
1 2
1 2
Output: 2
Example 3Sample Case
Input: 2
1 2
2 3
Output: 0
Constraints
Runtime Limit: 2000 ms per test batch
Memory Limit: 256 MB
Standard I/O stream reading
Official submissions are evaluated against hidden test cases on the server to verify time & memory complexity.