Skip to content

Practice Maximum Score Of Spliced Array

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2321
LeetCode Problem

Maximum Score Of Spliced Array

Problem Statement

You are given two 0-indexed integer arrays nums1 and nums2, both of length n. You can choose two integers left and right where 0 <= left <= right < n and swap the subarray nums1[left...right] with the subarray nums2[left...right]. You may choose to apply the mentioned operation once or not do anything. The score of the arrays is the maximum of sum(nums1) and sum(nums2), where sum(arr) is the sum of all the elements in the array arr. Return the maximum possible score. A subarray is a contiguous sequence of elements within an array. arr[left...right] denotes the subarray that contains the elements of nums between indices left and right (inclusive).

Source: Maximum Score Of Spliced Array on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums1 = [60,60,60], nums2 = [10,90,10]
Output
210

# Example 2

Input
nums1 = [20,40,20,70,30], nums2 = [50,20,50,40,20]
Output
220

# Example 3

Input
nums1 = [7,11,13], nums2 = [1,1,1]
Output
31

Constraints

n == nums1.length == nums2.length
1 <= n <= 10^5
1 <= nums1[i], nums2[i] <= 10^4

Related LeetCode Problems

Practice more problems similar to Maximum Score Of Spliced Array.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.