We have a sorting machine that works on a list of distinct numbers. This machine only has two instructions, named MOVEBACK and MOVEFRONT. Each instruction takes one element of the list as a parameter and removes that element from the list. MOVEBACK will then append that element to the end of the remaining list, while MOVEFRONT will insert it at the beginning.
For example, the sequence {8,12,25,7,15,19} can be sorted in ascending order using 2 instructions:
MOVEFRONT 7, to get {7,8,12,25,15,19}
MOVEBACK 25, to get {7,8,12,15,19,25}
You will be given a int[] a containing a list of distinct numbers. Return the minimum number of instructions required to sort the list in ascending order. |