Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
I timed out as well with this same solution. How did this one pass I wonder?
Offtopic but guess. You come from JavaScript? :D
whaaaat!!
very inefficient
I tried this one and it gave me time out error. Seems an inefficient way to do it?
I used permutations and got it to pass if you only compute all the permutations for the part of the number that needs changing.
You seem to create permutations for the entire number, for a number made up of 1234567890 I believe there are 9 billion of them. If you only use permutations on the part of the number that you are interested in, there are only 6. If you also sort them, you can exit once the permutation is lower than the original part of the number you cut out.
But you should really listend to the author of the kata above, there are much better ways than using permutations. I used it to iterate from a rough/working/inefficient solution to a better solution. Hope this helps.
Also, look for edge cases and cases where you can just swap 2 numbers to get the solution so you are not entering permuations at all.
For instance, I had
which doesn't make sense: should the return string be stripped or not?
Not a chance that might work (much less with a loop, not even a list comprehension); I would ask myself how to deal with it if you were a human.
This comment is hidden because it contains spoiler information about the solution
You don't need to import
math
, you can just usei**j
instead ofmath.pow(i, j)
.It is weird that your solution worked, I had a really similar one, and it always timed out. I had to add a
break
in myfor
loop to quit when I already reachedi
andj
such thati**j>n
.I think the description should mention that
add('0', '0')
, for instance, is supposed to return'0'
(it could beNone
,nill
,[]
, or whatever…)