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,664 views

in Online Assessments by Expert (108,170 points)
edited by | 1,664 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]

 

1<=N<=100000
by Expert (108,170 points)

Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .