Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Think of dynamic programming.
Define <code>dp[i][j][flag]</code> as the answer to the problem if we only consider the first <code>i</code> elements of the first array, the first <code>j</code> elements of the second array, and flag is either 0 or 1 indicating which array contains the largest element.