FastPrepPressure-Isolation Shutdown Order

Pressure-Isolation Shutdown Order

Intuit logoIntuit● HardNEW GRADINTERNOA
Learn

Problem statement

An offshore processing platform has n valves in a line. Valve i has signed pressure coefficient coefficients[i]. Permanent boundary regulators with coefficients leftBoundary and rightBoundary stand immediately outside the line and are never shut down.

Shut down every valve exactly once. When valve i is shut down, let x and y be the coefficients of its nearest valves or boundary regulators that are still active on its left and right. This shutdown adds x * coefficients[i] * y to the total stability score. Valve i is then removed, so later shutdowns may have different neighbors.

Return a two-element array: the maximum possible total stability score, followed by the number of distinct shutdown orders that attain that maximum. Report the number of orders modulo 10^9 + 7. Two orders are distinct when their valve-index sequences differ.

Function

maximizeStabilityAndCount(coefficients: int[], leftBoundary: int, rightBoundary: int) → long[]

Examples

Example 1

coefficients = [3]leftBoundary = 2rightBoundary = 5return = [30,1]

There is one shutdown order. Its only step contributes 2 * 3 * 5 = 30.

Example 2

coefficients = [1,1]leftBoundary = 1rightBoundary = 1return = [2,2]

Either valve can be shut down first. Both orders score 1 + 1 = 2, so there are two maximizing orders.

Example 3

coefficients = [1,2]leftBoundary = 1rightBoundary = 1return = [4,1]

Closing the first valve before the second scores 1 * 1 * 2 + 1 * 2 * 1 = 4. The other order scores 1 * 2 * 1 + 1 * 1 * 1 = 3.

Constraints

  • 1 <= coefficients.length <= 200.
  • -1000 <= coefficients[i], leftBoundary, rightBoundary <= 1000.
  • Use signed 64-bit arithmetic for stability scores and the returned score.
  • The returned count is reduced modulo 10^9 + 7.

More Intuit problems

See Intuit hiring insights
public long[] maximizeStabilityAndCount(int[] coefficients, int leftBoundary, int rightBoundary) {
  // Write your code here.
}
coefficients[3]
leftBoundary2
rightBoundary5
expected[30,1]
Checking account…