Skip to content

Practice Minimum Operations to Maximize Last Elements in Arrays

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

Medium#2934
LeetCode Problem

Minimum Operations to Maximize Last Elements in Arrays

Problem Statement

One operation swaps nums1[i] with nums2[i] at the same chosen index. Return the fewest operations needed so the last entry of nums1 is a maximum of nums1 and the last entry of nums2 is a maximum of nums2. Return -1 if impossible.

Source: Minimum Operations to Maximize Last Elements in Arrays on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums1 = [1,2,7], nums2 = [4,5,3]
Output
1

# Example 2

Input
nums1 = [2,3,4,5,9], nums2 = [8,8,4,4,4]
Output
2

# Example 3

Input
nums1 = [1,5,4], nums2 = [2,5,3]
Output
-1

Constraints

1 <= n == nums1.length == nums2.length <= 1000
1 <= nums1[i] <= 10^9
1 <= nums2[i] <= 10^9

Related LeetCode Problems

Practice more problems similar to Minimum Operations to Maximize Last Elements in Arrays.

Review your practice with PhantomCodeAI

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