+ 3

Python problem on end sorting

Can someone please help me understand the following question? I have uploaded my code. but it's showing errors. thanx Given a list A of N distinct integer numbers, you can sort the list by moving an element to the end of the list. Find the minimum number of moves required to sort the list using this method in ascending order.  Input Format: The first line of the input contains N distinct integers of list A separated by a space. Output Format Print the minimum number of moves required to sort the elements. Example: Input: 1 3 2 4 5 Output: 3 Explanation: In the first move, we move 3 to the end of the list. In the second move, we move 4 to the end of the list, and finally, in the third movement, we move 5 to the end. https://code.sololearn.com/cJfWwD08Qb9e/?ref=app

7th Mar 2019, 2:27 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
6 ответов
+ 4
You are not using l1 only l so your while loop is infinite because l will always have elements. Your algorithm doesn't match your requirements. https://code.sololearn.com/cm8Sj0xwOUyx
7th Mar 2019, 3:52 PM
John Wells
John Wells - avatar
+ 3
https://code.sololearn.com/cToLaSvlUbf2/?ref=app
7th Mar 2019, 6:03 PM
Anna
Anna - avatar
+ 1
John Wells sir can you please guide me??
7th Mar 2019, 2:29 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
+ 1
First up, your while loop is infinite. while l: means loop while the (in this case) list l is not empty. Since l is never empty, it never stops looping. Secondly, the algorithm in your code is incorrect. Since all elements are compared to your first element, and moved to the end if they are less than your first element, there is no way for the first element to be moved to the end if it is not the smallest. So that will also create an endless loop.
7th Mar 2019, 3:28 PM
Russ
Russ - avatar
+ 1
John Wells thanks a lot sir
7th Mar 2019, 6:12 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
+ 1
Anna thanx a lot mam
7th Mar 2019, 6:12 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar