Java 1D Array (Part 2)

  • + 4 comments

    import java.util.*;

    public class Solution {

    static int visited[];

    public static boolean canWin(int[] game,int leap,int i) { // Return true if you can win the game; otherwise, return false.

     if(i>=game.length)
               return true;
    
    if(visited[i]==0)
    {
        visited[i]=1;
        if(game[i]==0)
        {
    
           if( canWin(game,leap,i+leap))
               return true;
           if( canWin(game,leap,i+1))
           {
    
               return true;
           }
            if(i!=0)
                if( canWin(game,leap,i-1))
                     return true;
            }
    }
        return false;
    

    } public static void main(String[] args) { Scanner scan = new Scanner(System.in); int q = scan.nextInt(); while (q-- > 0) { int n = scan.nextInt(); int leap = scan.nextInt(); visited=new int[n]; int[] game = new int[n]; for (int i = 0; i < n; i++) { game[i] = scan.nextInt(); }

        System.out.println( (canWin(game,leap,0)) ? "YES" : "NO" );
    }
    scan.close();
    

    } }

    • + 1 comment

      hank you so much for this. I was into this issue and tired to tinker around to check if its https://plex.software possible but couldnt get it done. Now that i have seen the way you did it, thanks guys with regards

      • + 0 comments

        Thanks for sh https://kodi.software/ aring.I found a lot of interesting information here. A really good post, very thankful and hopeful that you will write many more posts like this one.

    • + 0 comments

      As hybrid application development with the mobile industry has a steady rise, mobile application development has become increasingly competitive. The pervasiveness of mobile devices and the widespread use of mobile applications among the global population has made smartphones a perfect avenue through which businesses can interact with their customers and clients. Companies can offer their products and services via mobile apps and significantly increase their customer base. As a result, the role of mobile application development in driving the growth of businesses has never been more important.