Skip to the code
+25 XP

#62 Best Multiplier Streak

medium

In a game, each round gives a whole-number multiplier in nums (zero or negative multipliers are bad luck). A combo multiplies the multipliers of back-to-back rounds.

Write bestComboProduct(nums) that returns the largest product of a run of at least one back-to-back round.

Example 1

Input: nums = [3,-1,4,-2]
Output: 24

The two negatives cancel out: 3 * -1 * 4 * -2 = 24.

Example 2

Input: nums = [-3,0,-1]
Output: 0

The single round with 0 beats every other run.

Constraints

  • 1 <= nums.length <= 2 * 10^5
  • -10 <= nums[i] <= 10
  • Every run's product fits in a safe integer.
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).