tictactoe problem failed this test case :
[[1,1],[2,0],[1,0],[2,1],[1,2]]
but ACCEPTED the code when submit
code :
'''
public static String solutiontictactoe(int[][] moves) {
String[][] tic = new String[3][3];
int i=0;
int count =1;
String winname = "Pending";
boolean winner = false;
if (moves.length < 5)
return "Pending";
count= fillIntoTictactoe(moves, tic);
i=0;
while (i<3)
{
// check horizontally
if ((tic[i][0] == tic[i][1] )&& (tic[i][1] == tic[i][2]))
{
if (tic[i][0] == null) {
winname="Pending";
break;}
winner = true;
winname = tic[i][0];
break;
}
// check vertically
if ((tic[0][i]== tic[1][i]) && (tic[1][i] == tic[2][i]))
{
if (tic[0][i] == null) { winname = "Pending";break;}
winner = true;
winname =tic [0][i];
break;
}
i++;
}
// check diagonally both ways
if ((tic[0][0] == tic[1][1]) && (tic[1][1]== tic[2][2]))
{
if (tic[0][0] == null) winname = "Pending";
else {
winner = true;
winname = tic[0][0];
}
}
if ((tic[0][2] == tic[1][1]) && (tic[1][1] == tic[2][0]))
{
if (tic[0][2] == null) winname = "Pending";
else {
winner = true;
winname = tic[0][2];}
}
if (!winner && count >9)
return "Draw";
return winname;
}
public static int fillIntoTictactoe(int[][] moves, String[][] tic)
{
int row =0;
int col =0;
int count =1;
int i=0;
while ( i < moves.length){
row= moves[i][0];
col = moves[i][1];
if (count %2 ==1 )
tic[row][col] = "A";
else
tic[row][col] = "B";
i++;
count++;
}
return count;
}
'''