2934. Minimum Operations to Maximize Last Elements in Arrays
You are given two 0-indexed integer arrays,
nums1
andnums2
, both having lengthn
.You are allowed to perform a series of operations (possibly none).
In an operation, you select an index
i
in the range[0, n - 1]
and swap the values ofnums1[i]
andnums2[i]
.Your task is to find the minimum number of operations required to satisfy the following conditions:
nums1[n - 1]
is equal to the maximum value among all elements ofnums1
, i.e.,nums1[n - 1] = max(nums1[0], nums1[1], ..., nums1[n - 1])
.nums2[n - 1]
is equal to the maximum value among all elements ofnums2
, i.e.,nums2[n - 1] = max(nums2[0], nums2[1], ..., nums2[n - 1])
.Return an integer denoting the minimum number of operations needed to meet both conditions, or
-1
if it is impossible to satisfy both conditions.
1 | class Solution { |