We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Jumping on the Clouds
Jumping on the Clouds
Sort by
recency
|
3281 Discussions
|
Please Login in order to post a comment
Solution i have tried::: Java
We already know this input has a solution, therefore there can't be any consecutive '1's in the input. Worst case, a '1' 2 cells ahead forces us to short-jump but then we're guaranteed a long-jump. We can use this to solve the problem faster:
Here is problem solution in Python, Java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-jumping-on-the-clouds-problem-solution.html
In hindsight, this is just a straight application of the greedy algorithm Just make 2 jumps if you can. I wasn't sure of that so I treated this as a dynamic programming problem.