Given an integer array, separate its elements into two ordered streams according to their indices:
0, 2, 4, ....1, 3, 5, ....Initialize a running value of 0 for each stream. Process each stream independently, alternating between + and *; the first element is added, the second is multiplied, the third is added, and so on.
After every element has been processed, compare the two running values modulo 2:
"EVEN" when evenSum % 2 > oddSum % 2."ODD" when oddSum % 2 > evenSum % 2."NEUTRAL" when the two remainders are equal.The running values must use long, since repeated multiplication can realistically overflow an int on larger inputs.
public static String plusMultipleArray(int[] arr)
Input: arr = [1, 2, 3, 4]
Output: "EVEN"
Explanation: The even-index stream produces (0 + 1) * 3 = 3, while the odd-index stream produces (0 + 2) * 4 = 8; their remainders are 1 and 0, respectively.
Input: arr = [4, 3, 2, 1]
Output: "ODD"
Explanation: The even-index result is (0 + 4) * 2 = 8, and the odd-index result is (0 + 3) * 1 = 3, so the odd stream has the larger remainder modulo 2.
Input: arr = [2, 3, 4, 2]
Output: "NEUTRAL"
Explanation: The streams finish at 8 and 6; because both values have remainder 0 modulo 2, neither stream wins.