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.
O(1) solution. Awesome. Wish I would've figured it out. Very nice
This comment is hidden because it contains spoiler information about the solution
give some theory about this solution pls)
At first, I also performed the solution with a loop, but then I thought that it was known in advance how many times the ball would fly near the window, which means there must be a mathematical formula.
Exactly something I was expecting while solving this Kata with boring loop
Gotta get my maths skills up I guess
But it is an effective solution and have a constant time, when the traditional method has a linear time. So it is better, though the comprehensibility isn't good without comments, but perfomance is actually better
Converting to int makes the * 2 + 1 operations done in integer arithmetics, which probably ends up saving a few cpu cycles.
Also prevents warnings about losing precision when implicitly converting from double to int.
This solution does not actually pass the tests...
As mentioned, it should take into account the case where the ball bounces at the exact height of the window.
It would have been nice if it worked like this.
And I think that (int)floor() is redundant.
It is actually quite straightforward, if you know geometric sequence and logarithm base change formulas.
This shouldn't be considered "Best Practices", it's not easy to figure out what does it do.
Very "Clever" though.
Awesome!!! I am loving this place.
Best answer ever. GJ
Oh I missed the "strictly greater than" in the description. Thanks for reminding.
And it's considerate of you to notice the situation where floor(k) equals 0.
This comment is hidden because it contains spoiler information about the solution
Might be a mistake though...
For such case: h=30, bounce=0.5, window=15.
The answer should be 2, I guess.
Need to consider cases that the ball bounces back to the exact height of the window.(Just like the case provided above.)
Loading more items...