Question: you are given 2 arrays of size N. Each array contains numbers from 1 to N ( no repetition) We define 1 operation by :
you are given 2 arrays of size N.
Each array contains numbers from 1 to N ( no repetition)
We define 1 operation by :
1- you can pick any number from the array.
2- you can place the number at the start or end of the array.
you are required to convert the second array into the first one using a minimum number of operations.
INPUT FORMAT
N
FIRST ARRAY SECOND ARRAY
OUTPUT FORMAT
An integer denoting the number of operations
Example: Turn Array2 into Array1
Array1 = [4,2,3,1,5,6] Array2 = [3,1,4,6,5,2]
Returns 3:
Operation 1: Move 2 to beginning. Array2 = [2,3,1,4,6,5]
Operation 2: Move 4 to beginning. Array2 = [4,2,3,1,6,5]
Operation 3: Move 6 to end: Array2 = [4,2,3,1,5,6]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
