Loading...
Loading...
You are given two integer arrays current and desired of the same length. All values in current are distinct, and desired contains exactly the same values in a possibly different order.
Consider an operation where you remove the last element of current and insert it at any position in current. Inserting it back at the end is allowed.
Given that you can perform this operation any number of times, return the minimum number of operations needed to make current equal to desired.
If the two arrays are already equal, return 0.
Input: current = [2, 1, 3, 5, 4], desired = [2, 4, 1, 5, 3]
Output: 2
Explanation: Move 4 to index 1 to get [2, 4, 1, 3, 5]. Move 5 to index 3 to get [2, 4, 1, 5, 3].
Input: current = [1, 2, 3], desired = [1, 2, 3]
Output: 0
Explanation: The arrays are already equal.
Input: current = [1, 2, 3], desired = [3, 2, 1]
Output: 2
Explanation: Move 3 to the front to get [3, 1, 2]. Move 2 to index 1 to get [3, 2, 1].
current.length = desired.lengthcurrent[i] ≤109current are distinct.desired is a permutation of current.