Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Maximize Last Elements in Arrays

med
30 min
Try to solve the Minimum Operations to Maximize Last Elements in Arrays problem.

Statement

You are given two 00 indexed integer arrays, nums1 and nums2, both of length n.

In one operation, you can choose an index i such that 0≤i<n0 \leq i < n and swap the elements nums1[i] and nums2[i].

Your task is to find the minimum number of operations required to make nums1[n - 1] equal to the maximum element in nums1 and nums2[n - 1] equal to the maximum element in nums2.

Return the minimum number of operations needed to satisfy both conditions, or −1-1 if it is impossible.

Constraints:

  • 1≤n==1 \leq n == nums1.length ==== nums2.length ≤1000\leq 1000

  • 1≤1 \leq nums1[i] ≤109\leq 10^9

  • 1≤1 \leq nums2[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Maximize Last Elements in Arrays

med
30 min
Try to solve the Minimum Operations to Maximize Last Elements in Arrays problem.

Statement

You are given two 00 indexed integer arrays, nums1 and nums2, both of length n.

In one operation, you can choose an index i such that 0≤i<n0 \leq i < n and swap the elements nums1[i] and nums2[i].

Your task is to find the minimum number of operations required to make nums1[n - 1] equal to the maximum element in nums1 and nums2[n - 1] equal to the maximum element in nums2.

Return the minimum number of operations needed to satisfy both conditions, or −1-1 if it is impossible.

Constraints:

  • 1≤n==1 \leq n == nums1.length ==== nums2.length ≤1000\leq 1000

  • 1≤1 \leq nums1[i] ≤109\leq 10^9

  • 1≤1 \leq nums2[i] ≤109\leq 10^9