Problem · Array

Maximum Product of a Strictly Increasing Contiguous Subarray

Learn this problem
Mediuminfosys logoinfosysFULLTIMEOA

Problem statement

Given an integer array nums, choose a non-empty contiguous subarray whose values are in strictly increasing order.

A subarray nums[l..r] is eligible when nums[i] < nums[i + 1] for every index i from l through r - 1. A subarray containing one element is eligible.

Return the maximum product of the elements in any eligible subarray.

Function

maximumProductIncreasingSubarray(nums: int[]) → long

Examples

Example 1

nums = [2,3,4]return = 24

The entire array is strictly increasing, and its product is 2 * 3 * 4 = 24.

Example 2

nums = [3,2,4,5]return = 40

The increase breaks between 3 and 2. Within the increasing run [2,4,5], the subarray [2,4,5] has product 40, which is the maximum.

Example 3

nums = [-5,-4,-3]return = 20

The array is strictly increasing, but using every element gives -60. The eligible subarray [-5,-4] has product 20, which is larger than every other eligible product.

Constraints

  • 1 <= nums.length <= 100000
  • -1000000000 <= nums[i] <= 1000000000
  • The product of every eligible subarray fits in a signed 64-bit integer.

More infosys problems

drafts saved locally
public long maximumProductIncreasingSubarray(int[] nums) {
    // write your code here
}
nums[2,3,4]
expected24
checking account