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.
Mine solution is very similar, not sure why it isn't grouped here.
The only substantial impovement we can do is to avoid condition inside the while loop.
because 'bounce' is literally how much % of the way the ball is reaching up since it's last descent from 'h' (h * bounce = new height of the ball), not how much it's descending per bounce.
Subtract bounce from height?
Why not subtract instead of multiply? Intuitively, it feels like subtraction makes sense to me.
But if height was a negative number and bigger than window, multiplying it by bounce would cause an infinite loop. I think.
h <= 0 is not needed due to instructions
Neat!
Wow that was clever to put additional if statement inside the while loop. Thanks I learned something from this.
wow, so nice, I am too clever with for cycle
I had the same issue at first. Did you include: " if( h <= 0 || bounce >= 1 || bounce <= 0 || window >= h) return -1" I think my innefficiency at first was coming from not including it and the code getting stuck on a test case that I didnt check for in the above line of code.
I tried this exact solution and the server responded that the algorithm was way too inefficient. I understand it's not the optimal approach, but is the performance of this snippet so so so terrible?