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.
very smart
i did the same thing but with for loop,and even tho for loop has less time complexity,it still got timed out,and i dropped this approach
Is it best practice to change the value of a variable in the while loop condition?
This one shows very good and creative thinking.
Of course, but you need to remeber that this task is designed for starters.
" " is not the only whitespace
In productive code, I prefer
i - n
instead of usingi + (n * -1)
to avoid unnecessary computations. That was a long time ago but I think, I wanted to show how I came up to this solution.This comment is hidden because it contains spoiler information about the solution
oh sorry, I was thinking
i - n
and I have 1 unintentionally writteni - 1
Maybe it's not the same formula:
i + (n * -1) = i - n
You need n in your formula, otherwise you don't know how far you should rotate.
i - 1 won't work for n > 1 in my solution.
instead of the if statement you could've used
c += i % 2
directlywhy not use
i - 1
instead ofi + (n * -1)
?