Question
Bubble Shuffle Lili has just learned about bubble sort in her algorithm class. However, she is having a problem with the implementation of the algorithm.
Bubble Shuffle
Lili has just learned about bubble sort in her algorithm class. However, she is having a
problem with the implementation of the algorithm. Instead of sorting the array A, her
algorithm creates a jumbled shuffle B of the original array. Lili has lost track of how
many changes has been done to the array, so she has asked your help to find out what
is the minimal number of swaps needed to restore the given shuffled array into the original array. As in bubble sort, a swap can only be done on elements adjacent to one another.
Format Input
A single line with an integer N denoting the number of elements followed by 2 lines each
containing N elements denoting the shuffle array B and the original array A respectively.
Format Output
A single line with an integer denoting the minimal number of swaps needed to restore
the original array.
Constraints
1 N 10^3
1 Ai
, Bi 10^9
Each element in A and B does not appear more than once
It is guaranteed that each element of B exist in A
Sample Input 1
5
1 2 5 3 4
5 1 4 2 3
Sample Output 1
4
Sample Input 2
7
1 3 5 7 9 13 11
13 11 9 7 5 3 1
Sample Output 2
20
Note : Use C Language , Dont Use Stdlib as you can
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started