FastPrepRunning Union Length after Interval Uploads

Running Union Length after Interval Uploads

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA
Learn

Problem statement

Each row [left, right] uploads a continuous half-open interval [left, right) with left < right. Intervals may overlap or touch.

After every upload, return the total length covered by the union of all intervals seen so far.

Function

runningUnionLengths(uploads: long[][]) → long[]

Examples

Example 1

uploads = [[1,5],[3,8]]return = [4,7]

The second interval adds only its uncovered suffix.

Example 2

uploads = [[1,2],[5,9]]return = [1,5]

Disjoint lengths add.

Constraints

  • 1 <= uploads.length <= 2000
  • -10^12 <= left < right <= 10^12

More ZipRecruiter problems

See ZipRecruiter hiring insights
public long[] runningUnionLengths(long[][] uploads) {
    // Write your code here.
}
uploads[[1,5],[3,8]]
expected[4,7]
Checking account…