Plus Mult Array
Updated
Problem statement
Given an integer array A, split its elements by zero-based index into an even-index subsequence A[0], A[2], A[4], ... and an odd-index subsequence A[1], A[3], A[5], ....
Evaluate each subsequence from left to right. Multiply its first two values, add the third value, multiply by the fourth value, add the fifth value, and continue alternating addition and multiplication. Let R_even be the even-index result modulo 2, and let R_odd be the odd-index result modulo 2. Normalize each remainder to either 0 or 1, including when the evaluated expression is negative.
Return the array classification according to these rules:
- Return
"ODD"whenR_odd > R_even. - Return
"EVEN"whenR_even > R_odd. - Return
"NEUTRAL"whenR_even = R_odd.
Function
plusMultArray(A: int[]) → StringExamples
Example 1
A = [12,3,5,7,13,12]return = "NEUTRAL"For the even indices, R_even = (12 × 5 + 13) mod 2 = 73 mod 2 = 1. For the odd indices, R_odd = (3 × 7 + 12) mod 2 = 33 mod 2 = 1. The two remainders are equal, so the result is "NEUTRAL".
Example 2
A = [0,1,0,1,0,1,0,1,0,1]return = "ODD"The even-index subsequence is [0,0,0,0,0], whose alternating result is 0. The odd-index subsequence is [1,1,1,1,1], whose result is (((1 × 1) + 1) × 1) + 1 = 3, so R_odd = 1. Therefore the classification is "ODD".
Constraints
10 ≤ A.length ≤ 10^5-10^9 ≤ A[i] ≤ 10^9
More IBM Online Assessment questions
- Missing IntervalsOA · Seen Nov 2026
- Last Object Exit TimeOA · Seen Nov 2026
- Count Peaks and ValleysOA · Seen Nov 2026
- Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
- Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
- Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
- Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
- Tree Pythagorean TriplesOA · Seen Oct 2026
- Minimum Power-of-Two Removal OperationsOA · Seen Oct 2026
- Maximum Compatible Time WindowsOA · Seen Oct 2026
Similar questions at other companies
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions
- Costliest ChocolateRippling · OARippling interview questions
- Online No-Intercept Linear RegressionTwo Sigma · OATwo Sigma interview questions
- Progressive Tax CalculatorInteractive Brokers · OA
- 2020 Account Balance with Monthly Card FeesDRW · OADRW interview questions
- Array Challenge (QR Intern)Akuna Capital · OAAkuna Capital interview questions
- Latency Bucket CounterDatadog · OA · PHONE SCREENDatadog interview questions
- First Fibonacci Number at Least the Array SumBitGo · OABitGo interview questions
- Metro Fare With a Daily CapMicrosoft · OAMicrosoft interview questions