Maximize the Even-Odd Index Product Gap
Problem statement
Split an integer array by original 0-based index parity. From the even-index group, choose two distinct elements with maximum product. From the odd-index group, choose two distinct elements with minimum product.
Return the maximum even-index product minus the minimum odd-index product.
Function
maximizeParityProductGap(values: int[]) → longExamples
Example 1
values = [5,1,-4,7,3,-2,6,4]return = 44The even-index maximum product is 5 × 6 = 30 and the odd-index minimum product is 7 × -2 = -14.
Example 2
values = [1,2,3,4]return = -5The only even pair has product 3 and the only odd pair has product 8.
Constraints
4 <= values.length <= 200000- Both parity groups contain at least two values.
-10^9 <= values[i] <= 10^9
Source note: Interview prompt excerpt preserved as source evidence.