Java 1D Array (Part 2)

  • + 1 comment

    Can you please tell me what is the wrong with my code

    public static boolean canWin(int leap, int[] game) { // Return true if you can win the game; otherwise, return false. int i=0; int n=game.length; while(i < n) { if((i+leap<=n-1 && game[i+leap]==0) || i+leap==n-1) i=i+leap; else if((i+1<=n-1 && game[i+1]==0) || i+1==n-1) i=i+1; else if( i-1 >=1 && game[i-1]==0 ) i=i-1; else return false; if (i==n-1) return true; } return true;}

    • + 1 comment

      import java.util.; import java.io.;

      class Solution{ public static void main(String []argh){ int[][] arr = new int[10][10]; Scanner sc = new Scanner(System.in); for(int i=0;i<6;i++){ for(int j=0;j<6;j++){ arr[i][j]=sc.nextInt();

               }
           }
           int maxi=-100000;
           for(int i=0;i<6;i++){
               for(int j=0;j<6;j++){
                   if(i<=3 && j<=3){
                       int sum=arr[i][j]+arr[i][j+1]+arr[i][j+2]+(arr[i+1][j+1])+arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2];
                       if(sum>maxi) maxi=sum;
                   }
               }
           }
           System.out.println(maxi);
      }
      

      }

      • + 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.