Leetcode Problem 2158. Amount of New Area Painted Each Day

2158. Amount of New Area Painted Each Day

Leetcode Solutions

Jump Line

  1. Initialize a 1D array line representing the number line with a size large enough to cover all possible positions.
  2. Initialize an array res to store the amount of new area painted each day.
  3. Iterate over each interval in the paint array.
  4. For each interval, iterate from start to end.
  5. If the current position has not been painted (i.e., line[start] is 0), increment the count for the day and set line[start] to end.
  6. If the current position has been painted, jump to the end of the painted range recorded in line[start].
  7. Compress jumps by updating line[start] to the maximum of its current value and end.
  8. Continue until the entire interval has been processed.
  9. Return the res array containing the amount of new area painted each day.
UML Thumbnail

Merge Intervals with TreeMap

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...