You are given two arrays nums1 and nums2, both having the same length.
You are allowed to take any continuous segment (subarray) from nums1, temporarily remove it, and then insert that same segment back into nums1 at any position you choose (without changing the order inside the segment).
You may perform this operation multiple times.
Your goal is to transform nums1 so that it becomes exactly the same as nums2, using the minimum number of such operations.
Return that minimum number of operations.
Input: nums1 = [4,2,3,1], nums2 = [1,4,2,3]
Output: 1
Explanation:
Remove subarray [1] and insert it at the front → [1,4,2,3].
Input: nums1 = [7,8,9], nums2 = [7,8,9]
Output: 0
Explanation:
Arrays are already identical, so no operation is needed.
Input: nums1 = [5,3,2,4,1], nums2 = [1,5,3,2,4]
Output: 1
Explanation:
Extract [1] and move it to the front.
Accepted:
Submission: