first and second. Pick a non-empty subsequence from each (you may skip elements, but the rest keep their order), both of the same length.
Then pair the elements up in order (first with first, second with second, and so on) and add up the products of the pairs.
Return the largest value this sum can take.first=[4, -1, 2], second=[-3, 5] → 20
The best choice is a single pair: 4 from the first array and 5 from the second, 4 · 5 = 20. For instance, [-1, 2] with [-3, 5] gives only 3 + 10 = 13.
first=[-2, -5], second=[3, 4] → -6
Every product is negative and an empty choice is not allowed, so take the least bad pair: -2 · 3 = -6.
first=[4, -1, 2], second=[-3, 5]
20
Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.