Loading
Loading
A signal passes through a row of amplifier stages. Each stage multiplies the signal by an integer gain; a negative gain also inverts the signal, and a gain of 0 kills it. An engineer may tap the signal in and out around any contiguous run of stages, but must use at least one stage.
Return the largest product of gains over any contiguous run of stages.
factors = [2, -3, -2, 4, -1]2: high 2, low 2best 2-3: high -3, low -6the sign flips which is large-2: high 12, low 6(-6) × (-2) = 124: high 48, low 4best 48 = 2 × -3 × -2 × 4-1: high -4, low -48best stays 4848Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
2 × −3 × −2 × 4 = 48; including the final −1 would flip the sign.
Example 2
The 0 alone beats either negative stage.