So I agree that your solution works ( I didn't get the answer right myself ), and this is great stuff. I guess the answer to your question about the loops is the fact that there wasn't a guarantee (at first viewing) that looping thru just once would guarantee the optimal solution.
Great solution. I am a beginner in computer science can someone please confirm that the time complexity is O(3n * len(letters)) and if not could you explain me why? Many thanks
Thanks for this kata. I found it very challenging to keep track of whether starting zeros are OK or not, depending on where we are in the computation. I wonder if I missed an obvious optimization.
Yes, there is a similarity there. That one didn't show up when I was searching for possible duplicates before publishing. However, it appears there are significant differences that distinguish between the two so they wouldn't be duplicates.
It's a nice kata but I found it quite difficult to understand the instructions. I prefer very simple instructions that give rise to a difficult problem :) But still thanks for this!
Is the "somewhat satisfied" vote due to the ranking? Because I have no control over that.
I think this is harder than 5-kyu
This comment is hidden because it contains spoiler information about the solution
How about reducing the numbers of loop: len(letters) to its half?
I have absolutely no background in programming I had just learnt python from codecademy.com and somehow came across codewars to practise what I have learnt. I managed to reach 5kyu, so this question may sound silly but can someone explain the 2nd and 3rd line of the code, what does it exactly do?
Can anybody explain to me why the outer for-loop loops len(letter) times ?
Is it because each iteration through the outer for loop decides the final position of exactly one letter ?
My solution is similar except that I just kept the outer for loop going until the inner for loop resulted in no swaps at all.