You are given a 2D integer array intervals, where intervals[i] = [start, end] covers every integer coordinate from start to end inclusive.
Return how many distinct integer coordinates are covered by at least one interval. Coordinates covered by several intervals are counted once.
Examples
Example 1
Input: intervals = [[3,6],[1,5],[4,7]]
Output: 7
Explanation: Together the intervals cover the coordinates 1 through 7, so 7 coordinates are covered. The overlaps at 3, 4, 5, and 6 do not add to the count.
Example 2
Input: intervals = [[1,3],[5,8]]
Output: 7
Explanation: The first covers 1, 2, 3 and the second covers 5, 6, 7, 8. Coordinate 4 is covered by neither, so the total is 3 + 4 = 7.
Constraints
1≤intervals.length≤100
intervals[i].length=2
1≤start≤end≤100
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up