Maximum-Product Subarray with an Empty Choice
Updated
Problem statement
Choose a contiguous subarray of nums with the largest product. You may choose the empty subarray, whose product is 1.
Return its zero-based inclusive endpoints [start, end]. Return [-1, -1] for the empty choice. The endpoints identify the subarray itself; do not return only its product.
Compare products exactly. If several choices have the same product, choose the shortest; if their lengths also tie, choose the earliest start. So the empty choice wins every tie at product 1.
Each value has at most one digit after the decimal point, so 0.7 is exactly seven tenths. Values below 1, zero and negative values can all appear. The limits below make every product small enough to compare exactly.
Function
maxProductSegment(nums: double[]) → int[]Examples
Example 1
nums = [0.1,4,0.8,10,0.1,0.2]return = [1,3]The subarray [4,0.8,10] has product 32. Its inclusive endpoints are [1,3]; the interior 0.8 remains part of the product.
Example 2
nums = [0.5,0.2]return = [-1,-1]The nonempty products are 0.5, 0.2 and 0.1, all below the empty product 1.
Example 3
nums = [-2,3,-4]return = [0,2]The two negative values cancel out, so the product of all three values is 24, larger than every other choice.
Constraints
0 <= nums.length <= 100000-10 <= nums[i] <= 10- Each value is an integer multiple of
0.1. - Every nonempty contiguous product lies between
-1000000and1000000, inclusive, and is an integer multiple of0.000001.
More Akuna Capital Phone Screen questions
- Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Biased Coin: Probability of Exactly h HeadsPHONE SCREEN · Seen Nov 2026
- Positive Nth Root with Gradient DescentPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Two SumOA · PHONE SCREEN · Seen Sep 2026
- Maximum Value in a Binary TreePHONE SCREEN · Seen Sep 2026
- Tiered Expiring Item StorePHONE SCREEN · Seen Aug 2026
- Statistics for the Latest K ValuesPHONE SCREEN · Seen Nov 2025
- Remove Duplicates While Preserving OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025
- Sliding Window MaximumPHONE SCREEN · Seen Oct 2025
- Evaluate a PolynomialPHONE SCREEN · Seen Oct 2025
Similar questions at other companies
- Coin Game From The EndsTekion · PHONE SCREENTekion interview questions
- Knockout Tournament Win ProbabilityGoogle · PHONE SCREENGoogle interview questions
- Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
- Jump Game with Prime-3 StepsAgoda · OAAgoda interview questions
- Jump Game with Prime-3 StepsUber · OAUber interview questions
- Pascal's TriangleJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
- Fewest Coins CombinationBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Logistic Regression with Gradient DescentYahoo · PHONE SCREENYahoo interview questions
- Longest Increasing SubsequenceByteDance · PHONE SCREENByteDance interview questions
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
Interview reports that mention this question
Akuna Capital interview experiences
- Akuna Capital Quant Trader and QR Interviews: 5 Experiences
- Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
- Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
- Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
- Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)