As reported: Salesforce hiring drive (Nov 2025), round 1 (DSA).
You are given two integer arrays, array1 and array2 (length m). You make exactly m moves. In each move you take the element at the front or the back of array2, remove it, and insert it at the front or the back of array1.
The value of array1 is its maximum subarray sum (the largest sum of a non-empty contiguous subarray). Adding elements never lowers this value, so it is largest after the last move. Return the largest value array1 can have after all m moves, over all ways of making the moves.
Example 1
array1 = [1,3,-5,2,2], array2 = [2,3]
Output: 9
Appending both elements at the back gives [1,3,-5,2,2,2,3], where 2 + 2 + 2 + 3 = 9.
Example 2
array1 = [-1], array2 = [-3,5,-2]
Output: 5
Example 3
array1 = [-4,-6], array2 = [-2,-1]
Output: -1
Constraints: 1 ≤ array1.length, array2.length ≤ 10^5; -10^4 ≤ array1[i], array2[i] ≤ 10^4.
Code runner format: one JSON value per line: array1, then array2. Implement maxSubarrayAfterMoves(array1, array2); the harness prints the value.