In a video editor, a user selects several parts of the timeline. Each selection is [start, end] in seconds and covers the time from start up to end (a selection [2, 5] covers 3 seconds). Selections can overlap.
Write coveredSeconds(selections) that returns the total number of seconds covered by at least one selection. Overlapping time is counted once.
Input: selections = [[1,4],[2,6],[8,10]] Output: 7
[1, 4] and [2, 6] cover 1 to 6 (5 seconds), and [8, 10] adds 2.
Input: selections = [[0,10],[2,3]] Output: 10
The second selection is inside the first.
0 <= selections.length <= 1000000 <= start < end <= 10^9Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #584 Total Time Covered by Selections. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.