Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,611 views
in Online Assessments by Expert (108,190 points) | 1,611 views

1 Answer

0 like 0 dislike
Given two arrays of size N each containing the elements 1 to N, find the minimum number of operations needed to transform the second array into the first.

 

An operation is defined as:
Taking any current value in an array and moving it to the beginning or end.

 

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]
by Expert (108,190 points)