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
Amount of New Area Painted Each DayInput: [[1,4],[4,7],[5,8]]12345678Day 1: [1,4) → paint positions 1,2,3 → 3 newDay 2: [4,7) → paint positions 4,5,6 → 3 newDay 3: [5,8) → positions 5,6 already painted, only 7 new → 1 newalready paintedOutput: [3,3,1]
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!
Asked in
Google 25 Amazon 18 Microsoft 12
34.5K Views
Medium Frequency
~35 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen