Java 1D Array (Part 2)

  • + 5 comments

    Here's a test case from the problem:

    6 5
    0 0 0 1 1 1
    

    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.

    • + 1 comment

      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

      • + 1 comment

        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.

        • + 0 comments

          Same problem which we all are solving.I need suggestion in my code

    • + 0 comments

      Great explanation, thanks.

    • + 1 comment

      Thanks. But why is it trying to do the third recursion(isSolvable(array, m, i - 1)) first?

      • + 0 comments

        I updated/fixed my original explanation.

        HackerRank solutions

    • + 0 comments

      You explained perfectly :]

    • + 1 comment

      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?

      • [deleted]
        + 0 comments

        A leap of 5 from index 1 will take you off the end of the array, thus you win.

        [1] visited
        [0] we're here
        [0] + 1
        [1] + 2
        [1] + 3
        [1] + 4
            + 5