Problem · Array

Find Shared Camera Activity Periods

Learn this problem
MediumServal logoServalFULLTIMEPHONE SCREEN

Problem statement

You are given timestamp-sorted intensity readings for one or more cameras. For camera c, timestamps[c][i] and intensities[c][i] describe reading i. A reading is active when its intensity is at least threshold.

Within one camera, a maximal consecutive run of active readings forms a closed period from the first reading's timestamp through the last reading's timestamp. An inactive reading ends the current run.

Return the maximal closed time periods during which every camera is active. Compute each camera's periods and intersect them. For this exercise, assume a one-reading run is [timestamp,timestamp]. A camera with no active period makes the result empty. Merge final closed fragments that overlap or touch at one endpoint.

Function

findSharedActivityPeriods(timestamps: int[][], intensities: double[][], threshold: double) → List<List<Integer>>

Examples

Example 1

timestamps = [[1,5,11,15,17,20,27,31,36]]intensities = [[0.4,0.2,0.9,0.9,0.8,0.3,0.9,1.0,0.8]]threshold = 0.8return = [[11,17],[27,36]]

The readings at timestamps 11, 15, 17 are consecutive and active, then timestamp 20 ends that run. The readings at 27, 31, 36 form the second run. Values equal to the threshold qualify.

Example 2

timestamps = [[1,4,7,10,13],[2,4,6,11,13]]intensities = [[0.9,0.9,0.2,0.9,0.9],[0.8,0.9,0.1,0.85,0.95]]threshold = 0.8return = [[2,4],[11,13]]

The first camera is active on [1,4] and [10,13]. The second is active on [2,4] and [11,13]. Their closed intersections are [2,4] and [11,13].

Example 3

timestamps = [[1,5,9],[5,6]]intensities = [[0.2,0.8,0.1],[0.9,0.1]]threshold = 0.8return = [[5,5]]

Each camera has an active period containing only timestamp 5, so their closed intersection is the singleton period [5,5].

Constraints

  • 1 <= timestamps.length == intensities.length <= 20
  • For every camera c, timestamps[c].length == intensities[c].length.
  • The total number of readings across all cameras is at most 200000.
  • Each camera's timestamps are strictly increasing integers between 0 and 10^9.
  • 0.0 <= intensities[c][i] <= 1.0 and 0.0 <= threshold <= 1.0.
drafts saved locally
public List<List<Integer>> findSharedActivityPeriods(int[][] timestamps, double[][] intensities, double threshold) {
    // Write your code here.
}
timestamps[[1,5,11,15,17,20,27,31,36]]
intensities[[0.4,0.2,0.9,0.9,0.8,0.3,0.9,1.0,0.8]]
threshold0.8
expected[[11,17],[27,36]]
checking account