3690. Split and Merge Array Transformation Medium

@problem@discussion
#Array#Hash Table#Breadth-First Search



1/**
2 * [3690] Split and Merge Array Transformation
3 *
4 * You are given two integer arrays nums1 and nums2, each of length n. You may perform the following split-and-merge operation on nums1 any number of times:
5 * <ol>
6 * 	Choose a subarray nums1[L..R].
7 * 	Remove that subarray, leaving the prefix nums1[0..L-1] (empty if L = 0) and the suffix nums1[R+1..n-1] (empty if R = n - 1).
8 * 	Re-insert the removed subarray (in its original order) at any position in the remaining array (i.e., between any two elements, at the very start, or at the very end).
9 * </ol>
10 * Return the minimum number of split-and-merge operations needed to transform nums1 into nums2.
11 *  
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">nums1 = [3,1,2], nums2 = [1,2,3]</span>
15 * Output: <span class="example-io">1</span>
16 * Explanation:
17 * 
18 * 	Split out the subarray [3] (L = 0, R = 0); the remaining array is [1,2].
19 * 	Insert [3] at the end; the array becomes [1,2,3].
20 * </div>
21 * <strong class="example">Example 2:
22 * <div class="example-block">
23 * Input: <span class="example-io">nums1 = </span>[1,1,2,3,4,5]<span class="example-io">, nums2 = </span>[5,4,3,2,1,1]
24 * Output: 3
25 * Explanation:
26 * 
27 * 	Remove [1,1,2] at indices 0 - 2; remaining is [3,4,5]; insert [1,1,2] at position 2, resulting in [3,4,1,1,2,5].
28 * 	Remove [4,1,1] at indices 1 - 3; remaining is [3,2,5]; insert [4,1,1] at position 3, resulting in [3,2,5,4,1,1].
29 * 	Remove [3,2] at indices 0 - 1; remaining is [5,4,1,1]; insert [3,2] at position 2, resulting in [5,4,3,2,1,1].
30 * </div>
31 *  
32 * Constraints:
33 * 
34 * 	2 <= n == nums1.length == nums2.length <= 6
35 * 	-10^5 <= nums1[i], nums2[i] <= 10^5
36 * 	nums2 is a permutation of nums1.
37 * 
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/split-and-merge-array-transformation/
42// discuss: https://leetcode.com/problems/split-and-merge-array-transformation/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47    pub fn min_split_merge(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 {
48        0
49    }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[test]
59    fn test_3690() {
60    }
61}
62

Back
© 2026 bowen.ge All Rights Reserved.