801. Minimum Swaps To Make Sequences Increasing Hard
1/**
2 * [801] Minimum Swaps To Make Sequences Increasing
3 *
4 * 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].
5 *
6 * For example, if nums1 = [1,2,3,<u>8</u>], and nums2 = [5,6,7,<u>4</u>], you can swap the element at i = 3 to obtain nums1 = [1,2,3,4] and nums2 = [5,6,7,8].
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.
9 * An array arr is strictly increasing if and only if arr[0] < arr[1] < arr[2] < ... < arr[arr.length - 1].
10 *
11 * Example 1:
12 *
13 * Input: nums1 = [1,3,5,4], nums2 = [1,2,3,7]
14 * Output: 1
15 * Explanation:
16 * Swap nums1[3] and nums2[3]. Then the sequences are:
17 * nums1 = [1, 3, 5, 7] and nums2 = [1, 2, 3, 4]
18 * which are both strictly increasing.
19 *
20 * Example 2:
21 *
22 * Input: nums1 = [0,3,5,8,9], nums2 = [2,1,4,6,9]
23 * Output: 1
24 *
25 *
26 * Constraints:
27 *
28 * 2 <= nums1.length <= 10^5
29 * nums2.length == nums1.length
30 * 0 <= nums1[i], nums2[i] <= 2 * 10^5
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing/
36// discuss: https://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn min_swap(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 {
42 0
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_801() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.