FastPrepMaximize the Even-Odd Index Product Gap

Maximize the Even-Odd Index Product Gap

Infosys logoInfosys● MediumNEW GRADONSITE INTERVIEW
Learn

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[]) → long

Examples

Example 1

values = [5,1,-4,7,3,-2,6,4]return = 44

The 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 = -5

The 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.

More Infosys problems

See Infosys hiring insights
public long maximizeParityProductGap(int[] values) {
    // Write your code here.
}
values[5,1,-4,7,3,-2,6,4]
expected44
Checking account…