454. Amount of New Area Painted Each Day
There is a long, narrow strip that can be visualized as a number line. Given a 0-indexed 2D integer array paint of size n, where paint[i] = [starti, endi], it signifies that on the i-th day, you need to paint the segment covering all integer points in [starti, endi), i.e. starting at start_i inclusive and ending at end_i exclusive.
To ensure an even coat, any section should only be painted once.
Return an integer array worklog of size n, where worklog[i] represents the newly painted length on the i-th day.
Example 1:
Input: paint = [[5,8],[1,5],[7,10]]
Output: [3,4,2]
Explanation:
On day 0, the segment between 5 and 8 is painted, covering 8 - 5 = 3 units.
On day 1, the section from 1 to 5 is painted, contributing 5 - 1 = 4 new units.
On day 2, the segment 7 to 10 is painted, but 7 to 8 was already painted on day 0, so only 10 - 8 = 2 new unit is added.
Example 2:
Input: paint = [[1,7],[4,6]]
Output: [6,0]
Explanation:
Day 0: Paint from 1 to 7, covering 6 units.
Day 1: Paint from 4 to 6, but this section was already painted on day 0, so 0 new units are added.
Now Your Turn!
Pick the correct output for the given inputInput: paint = [[2,6],[3,7],[5,8]]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= paint.length <= 105
- paint[i].length == 2
- 0 <= starti < endi <= 5 * 104