Grids to store the possible grids
char [ ] [ ] gridTest1 = new char [ N ] [ 1001 ] ; char [ ] [ ] gridTest2 = new char [ N ] [ 1001 ] ; createGrid ( gridTest1 , true , N , M ) ; createGrid ( gridTest2 , false , N , M ) ; if ( testGrid ( gridTest1 , grid , N , M ) ) { System . out . println ( " Yes " ) ; printGrid ( gridTest1 , N , M ) ; } else if ( testGrid ( gridTest2 , grid , N , M ) ) { System . out . println ( " Yes " ) ; printGrid ( gridTest2 , N , M ) ; } else { System . out . println ( " No " ) ; } }