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.
6 characters longer than my solution :D (ignoring the newlines added for legibility)
The sorting is not done on the same n (input length), so I don't think you're right in that it's O(n log n)
Hint #1 is very good.
nice, walrus is great
It's a variable assigned using the (relatively) new walrus operator := in Python; you can read more about it here for example:
https://docs.python.org/3/whatsnew/3.8.html
Basically it allows you to assign variables in the middle of expressions.
You could have written
''.join(' ' * ( abs(n // 2 - i)) + '*' * (n - 2 * abs(n // 2 - i)) + '\n' for i in range(n)) if n > 0 and n % 2 else None
why have you chose variable t:= ?
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
@quint Impressive, but looks overly mathematical for the task... I'd stay with the slower solution for the sake of readability.
agreed. also an edge case test: ",,treat"
, is not alphabetical
yea, I changed the while to a for loop and the 6k one is faster almost always but the time difference is still in the same range and fluctuates wildly. I never realized that while loops are slower than for loops in python, ty for letting me know
you're comparing a while loop and a for one. In python, they behave differently about the perfs (while is slower) => those checks are meaningless in the current state.
also I have no idea why my reply got posted twice
hmm, the results of comparing the two often turns out to be wildly inconsistent in time difference but remains in the 1-10µs range, tho I found that the n = 19 and 1009 takes longer with 2k, n = 10000000019 takes less with the 2k one most of the time. Code used for testing:
Loading more items...