Skip to the code
+25 XP

#497 Largest Scale Multiplier Run

medium

An animation chains scale transforms, and factors[i] is the whole-number multiplier of step i. A negative factor flips the element.

Write largestProductRun(factors) that returns the largest product of a run of one or more consecutive factors.

Example 1

Input: factors = [3,2,-3,5]
Output: 6

The run [3, 2] gives 6. Adding -3 makes it negative.

Example 2

Input: factors = [-3,0,-2]
Output: 0

Every run with two or more factors includes the 0, and the single factors are -3, 0, and -2.

Constraints

  • 1 <= factors.length <= 200000
  • -10 <= factors[i] <= 10
  • The product of every run of consecutive factors is between -10^15 and 10^15, so it fits exactly in a JavaScript number.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).