0

How to end- sort a list of distinct integers by using minimum number of moves?

Given a list of distinct N integer numbers seperated by a space,We need to sort the list by moving an element to the end of the list in minumum number of moves. > The output should be the value of minimum number of moves required to sort the list. For example Consider the example 1 3 5 2 6 as input.. First we move 3 to the end so that list becomes 1 5 2 6 3. Next we move 5 to the end so that the list becomes 1 2 6 3 5. Finally we move 6 to the end so that the list gets sorted and becomes 1 2 3 5 6. **Note:-**We didnt move 2 here cause it will add unnecesary moves and causes tue program to fail. I have tried an algorithm but its of no use. You can find my code below. The problem is whenever Im tryin to run that code,Iam getting a number which is not the least number of moves in which the array can be sorted. Is there any other algorithm to do this. Thanks in advance.

7th Mar 2019, 4:28 AM
Saicharan Pedapati
Saicharan Pedapati - avatar
2 ответов
+ 5
7th Mar 2019, 4:52 AM
Anna
Anna - avatar
+ 2
Aside from not having code to see, it sounds like it's some kind of variation of an insertion sort. Try looking into that.
7th Mar 2019, 5:00 AM
Austin