Museum Zone Boundary Atlas
Valid second-cut ranges per first cut for constrained three-part array splits
A museum has a straight corridor of rooms. Room k has a nonnegative conservation exposure score exposure[k].
The curator wants to divide all rooms into three nonempty, contiguous zones, in their original order. A division is described by two room counts i and j:
- The first zone contains rooms with indices
0throughi - 1. - The middle zone contains rooms with indices
ithroughj - 1. - The last zone contains rooms with indices
jthroughn - 1.
Let their total exposure scores be A, B, and C. A division is acceptable only when:
- The three zone lengths are at least
min_rooms[0],min_rooms[1], andmin_rooms[2], respectively. B >= first_factor * A.C >= last_factor * B.
Build a boundary atlas for every possible first boundary i from 1 through n - 2. Return a list of n - 2 pairs, where the pair at index i - 1 is:
[smallest_j, largest_j]if at least one acceptable division uses that first boundary;[-1, -1]otherwise.
Because exposure scores are nonnegative, every integer between smallest_j and largest_j is also an acceptable second boundary for that i. Boundaries are room counts, not zero-based room indices.
Examples
Example 1
Input: exposure = [1,1,1,1,1,1], min_rooms = [1,1,1], first_factor = 1, last_factor = 1 Output: [[2,3],[4,4],[-1,-1],[-1,-1]]
With equal room scores and factors of one, the middle zone must contain at least as much exposure as the first zone, while the last must contain at least as much as the middle. An early first boundary can therefore allow multiple second boundaries.
Example 2
Input: exposure = [0,0,0,0,0,0,0], min_rooms = [2,2,1], first_factor = 4, last_factor = 3 Output: [[-1,-1],[4,6],[5,6],[6,6],[-1,-1]]
All exposure totals are zero, so both exposure inequalities hold regardless of the factors. Only the minimum zone lengths restrict the boundary ranges.
Example 3
Input: exposure = [8,1,1,1,1], min_rooms = [1,1,1], first_factor = 2, last_factor = 1 Output: [[-1,-1],[-1,-1],[-1,-1]]
The large exposure in the first room cannot be followed by a middle zone with twice that exposure. Consequently, no first boundary admits an acceptable division.
Constraints
- 3 <= exposure.length <= 15000
- 0 <= exposure[k] <= 1000000
- min_rooms.length == 3
- 1 <= min_rooms[k] <= exposure.length
- 1 <= first_factor <= 10
- 1 <= last_factor <= 10
- The minimum zone lengths are not guaranteed to admit a division.
An O(n) time solution with O(n) space, including prefix sums and the returned atlas, is expected. Use sufficiently wide arithmetic for multiplied exposure totals.
Hints
Show hint 1Hint 1
Let P[t] be the total exposure of the first t rooms. For a fixed first boundary i, rewrite both exposure inequalities as bounds on P[j].
Show hint 2Hint 2
As i increases, both exposure bounds move monotonically. Maintain separate pointers for the first prefix meeting the lower bound and the first prefix exceeding the upper bound.
Follow-up questions
What an interviewer might ask once you have a working solution.
- How would you compute only the total number of acceptable divisions without constructing the atlas?
- If negative exposure scores were allowed, which interval and monotonicity properties would fail?
Practice this with an AI interviewer
Explain your approach out loud, write Python or JavaScript, run it against hidden tests (including large inputs), and get a scored debrief.
Start this problem