java.lang.Object
g2301_2400.s2321_maximum_score_of_spliced_array.Solution

public class Solution extends Object
2321 - Maximum Score Of Spliced Array.<p>Hard</p> <p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, both of length <code>n</code>.</p> <p>You can choose two integers <code>left</code> and <code>right</code> where <code>0 <= left <= right < n</code> and <strong>swap</strong> the subarray <code>nums1[left...right]</code> with the subarray <code>nums2[left...right]</code>.</p> <ul> <li>For example, if <code>nums1 = [1,2,3,4,5]</code> and <code>nums2 = [11,12,13,14,15]</code> and you choose <code>left = 1</code> and <code>right = 2</code>, <code>nums1</code> becomes <code>[1, **&lt;ins&gt;12,13&lt;/ins&gt;** ,4,5]</code> and <code>nums2</code> becomes <code>[11, **&lt;ins&gt;2,3&lt;/ins&gt;** ,14,15]</code>.</li> </ul> <p>You may choose to apply the mentioned operation <strong>once</strong> or not do anything.</p> <p>The <strong>score</strong> of the arrays is the <strong>maximum</strong> of <code>sum(nums1)</code> and <code>sum(nums2)</code>, where <code>sum(arr)</code> is the sum of all the elements in the array <code>arr</code>.</p> <p>Return <em>the <strong>maximum possible score</strong></em>.</p> <p>A <strong>subarray</strong> is a contiguous sequence of elements within an array. <code>arr[left...right]</code> denotes the subarray that contains the elements of <code>nums</code> between indices <code>left</code> and <code>right</code> ( <strong>inclusive</strong> ).</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums1 = [60,60,60], nums2 = [10,90,10]</p> <p><strong>Output:</strong> 210</p> <p><strong>Explanation:</strong> Choosing left = 1 and right = 1, we have nums1 = [60,<ins> <strong>90</strong> </ins>,60] and nums2 = [10,<ins> <strong>60</strong> </ins>,10].</p> <p>The score is max(sum(nums1), sum(nums2)) = max(210, 80) = 210.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums1 = [20,40,20,70,30], nums2 = [50,20,50,40,20]</p> <p><strong>Output:</strong> 220</p> <p><strong>Explanation:</strong> Choosing left = 3, right = 4, we have nums1 = [20,40,20,<ins> <strong>40,20</strong> </ins>] and nums2 = [50,20,50,<ins> <strong>70,30</strong> </ins>].</p> <p>The score is max(sum(nums1), sum(nums2)) = max(140, 220) = 220.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums1 = [7,11,13], nums2 = [1,1,1]</p> <p><strong>Output:</strong> 31</p> <p><strong>Explanation:</strong> We choose not to swap any subarray.</p> <p>The score is max(sum(nums1), sum(nums2)) = max(31, 3) = 31.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == nums1.length == nums2.length</code></li> <li><code>1 <= n <= 10<sup>5</sup></code></li> <li><code>1 <= nums1[i], nums2[i] <= 10<sup>4</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maximumsSplicedArray

      public int maximumsSplicedArray(int[] nums1, int[] nums2)