Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    801 - Minimum Swaps To Make Sequences Increasing\.

    Hard

    You are given two integer arrays of the same length nums1 and nums2. In one operation, you are allowed to swap nums1[i] with nums2[i].

    • For example, if <code>nums1 = 1,2,3,<ins>8</ins></code>, and <code>nums2 = 5,6,7,<ins>4</ins></code>, you can swap the element at i = 3 to obtain nums1 = [1,2,3,4] and nums2 = [5,6,7,8].

    Return the minimum number of needed operations to make nums1 and nums2 strictly increasing. The test cases are generated so that the given input always makes it possible.

    An array arr is strictly increasing if and only if arr[0] &lt; arr[1] &lt; arr[2] &lt; ... &lt; arr[arr.length - 1].

    Example 1:

    Input: nums1 = 1,3,5,4, nums2 = 1,2,3,7

    Output: 1

    Explanation: Swap nums13 and nums23. Then the sequences are: nums1 = 1, 3, 5, 7 and nums2 = 1, 2, 3, 4 which are both strictly increasing.

    Example 2:

    Input: nums1 = 0,3,5,8,9, nums2 = 2,1,4,6,9

    Output: 1

    Constraints:

    • <code>2 <= nums1.length <= 10<sup>5</sup></code>

    • nums2.length == nums1.length

    • <code>0 <= nums1i, nums2i<= 2 * 10<sup>5</sup></code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer minSwap(IntArray listA, IntArray listB)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait