Minimum move to front operations
Submissions: 293   Accuracy:

34.13%

  Difficulty: Basic   Marks: 1

Given an array arr[] of size n such that array elements are distinct and in the range from 1 to n. The task is to count minimum number of move-to-front operations to arrange items as {1, 2, 3,… n}. The "move-to-front" operation is to pick any element arr[i] and place it at first position.

Input:
First line consists of T test cases. First line of every test case consists of N, denoting the number of elements of array. Second line of every test case consists of elements of array.

Output:
Single line output i.e minimum number of move to front operation to sort the array.

Constraints:
1<=T<=100
1<=N<=100
1 <= arr[i] <= N

Example:
Input:

2
4
3 2 1 4
7
5 7 4 3 2 6 1
Output:
2
6

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Anuj Chauhan
Author: anuj0503


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.