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.
Our array is of size 6, our step size m = 5, and the array is shown above.
We start at index 0.
First, it tries to take a step of size 5, and fails (since there's a 1 there). Then it tries taking a step forward "i+1", and it works (since there's a 0 there). So now we're at index 1 in the array.
Now it can take a leap of size m = 5, and succeed.
I see your solution, but which question is that? If it's in any of the following tracks:
10 Days of Statistics
30 Days of Code
Algorithms
Cracking the Coding Interview
Data Structures
Java
then I may already have posted the solution in HackerRank solutions. If it's a question from any of those tracks I can go ahead and try to solve it for you. If it's from a different track I can get to it after I finish completing the above tracks.
From index 1,how can u take a leap 5?
As per question, lead can be added only if the destination value is zero.
But here, (index1) 0 + 5 (leap) = 1(index 5) -where the destination value is not zero. Then, how can this move be possible?
Java 1D Array (Part 2)
You are viewing a single comment's thread. Return to all comments →
Here's a test case from the problem:
Our array is of size 6, our step size m = 5, and the array is shown above.
We start at index 0.
First, it tries to take a step of size 5, and fails (since there's a 1 there). Then it tries taking a step forward "i+1", and it works (since there's a 0 there). So now we're at index 1 in the array.
Now it can take a leap of size m = 5, and succeed.
HackerRank solutions.
Hi, I am facing problem while soving it .Can you provide the generilized solution or algo for it.
https://github.com/rsamrat073/HackerRank/blob/master/ArrayHopping
I see your solution, but which question is that? If it's in any of the following tracks:
then I may already have posted the solution in HackerRank solutions. If it's a question from any of those tracks I can go ahead and try to solve it for you. If it's from a different track I can get to it after I finish completing the above tracks.
Same problem which we all are solving.I need suggestion in my code
Great explanation, thanks.
Thanks. But why is it trying to do the third recursion(isSolvable(array, m, i - 1)) first?
I updated/fixed my original explanation.
HackerRank solutions
You explained perfectly :]
From index 1,how can u take a leap 5? As per question, lead can be added only if the destination value is zero. But here, (index1) 0 + 5 (leap) = 1(index 5) -where the destination value is not zero. Then, how can this move be possible?
A leap of 5 from index 1 will take you off the end of the array, thus you win.