Amount of New Area Painted Each Day - Problem
There is a long and thin painting that can be represented by a number line. You are given a 0-indexed 2D integer array paint of length n, where paint[i] = [starti, endi].
This means that on the i-th day you need to paint the area between starti and endi. Painting the same area multiple times will create an uneven painting so you only want to paint each area of the painting at most once.
Return an integer array worklog of length n, where worklog[i] is the amount of new area that you painted on the i-th day.
Input & Output
Example 1 — Basic Overlapping
$
Input:
paint = [[1,4],[4,7],[5,8]]
›
Output:
[3,3,1]
💡 Note:
Day 1: paint [1,4) → 3 new units. Day 2: paint [4,7) → 3 new units. Day 3: paint [5,8) → only position 7 is new (positions 5,6 already painted) → 1 new unit.
Example 2 — Complete Overlap
$
Input:
paint = [[1,4],[2,3],[4,6]]
›
Output:
[3,0,2]
💡 Note:
Day 1: paint [1,4) → 3 new units. Day 2: paint [2,3) → completely inside [1,4), 0 new units. Day 3: paint [4,6) → 2 new units.
Example 3 — No Overlap
$
Input:
paint = [[1,2],[3,4],[5,6]]
›
Output:
[1,1,1]
💡 Note:
All intervals are disjoint, each day paints exactly 1 new unit.
Constraints
- 1 ≤ paint.length ≤ 2 × 104
- paint[i].length == 2
- 0 ≤ starti < endi ≤ 5 × 104
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array of [start,end) painting intervals for each day
2
Process
Track painted areas, count only new unpainted regions
3
Output
Array of new areas painted each day
Key Takeaway
🎯 Key Insight: Only count unpainted areas when painting new intervals - avoid double painting!
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code