FastPrepLargest Product Stretch and Its Bounds
Problems/Largest Product Stretch and Its Bounds

Largest Product Stretch and Its Bounds

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem asks for the contiguous stretch with the largest product together with where it starts and ends. In an Adobe MTS-2 report, the first round asked for the product alone (given only as a link) and then also wanted the stretch itself; nothing else is said about it.

Our choices: the answer is [product, start, end]; ties go to the shortest stretch and then the earliest start; values are from -10 to 10, there are at most 2000 of them, every stretch without a 0 has an absolute product of at most 10^18, and the examples are new.

The judged task matches the report at about 85%.

Given an integer array nums, find a non-empty contiguous stretch nums[start..end] whose product is as large as possible.

If several stretches reach that largest product, choose the shortest one; if several of those are equally short, choose the one with the smallest start.

Return [product, start, end] (indexes from 0, both ends included).

Function

maxProductSubarray(nums: int[]) → long[]

Examples

Example 1

nums = [2,-5,3,4,-1]return = [120,0,4]

The whole array has two negative values, so its product is positive: 2 × (-5) × 3 × 4 × (-1) = 120. No other stretch beats it, so the answer is [120, 0, 4].

Example 2

nums = [1,3,1,0,3]return = [3,1,1]

The largest product is 3. Several stretches reach it: [3] at index 1, [1,3], [3,1], [1,3,1] and [3] at index 4. The shortest have length 1, and the leftmost of those starts at index 1, so the answer is [3, 1, 1].

Example 3

nums = [-4,0,-2]return = [0,1,1]

Every stretch with a negative product loses to the single 0, whose product 0 is the largest. The answer is [0, 1, 1].

Constraints

  • 1 <= nums.length <= 2000
  • -10 <= nums[i] <= 10
  • In every stretch of nums that contains no 0, the product of the absolute values is at most 10^18, so every product fits in a 64-bit integer.

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public long[] maxProductSubarray(int[] nums) {
    // Write your code here.
}
Checking account…