From 4193b38cd7f99d97b604dc1a0113abfdeeb7c0b9 Mon Sep 17 00:00:00 2001 From: SouravD12 Date: Fri, 1 Dec 2023 18:02:26 +0530 Subject: [PATCH] isValidSudoku --- .idea/misc.xml | 2 +- .idea/workspace.xml | 47 +++++---- checkValidSudoku.java | 110 +++++++++++++++++++++ out/production/OpenSourceForAll/Main.class | Bin 516 -> 516 bytes 4 files changed, 139 insertions(+), 20 deletions(-) create mode 100644 checkValidSudoku.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 6989bdc..fce02b5 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,7 @@ - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5bddc67..bc3b0d4 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,11 +1,14 @@ + + - + + + - - + + + @@ -34,12 +44,16 @@ + + + @@ -51,23 +65,17 @@ - - - - - - - + + + + diff --git a/checkValidSudoku.java b/checkValidSudoku.java new file mode 100644 index 0000000..7836db2 --- /dev/null +++ b/checkValidSudoku.java @@ -0,0 +1,110 @@ +// Hi i needed help with this problem most of the test cases are running correctly , only 30 test cases are failing out of 503 +// 473 has worked properly , need assistance with the issue and please help me understand where i am wrong . +// I have added all test case that is failing at the end of the code + +import java.util.HashMap; +class checkValidSudoku { + public boolean isValidSudoku(char[][] board) { + int m = board.length; // ---> Checked the size of Sudoku board in length + int n = board[0].length; // ---> Checked the size of sudoku board in width + // for(int a =0;a<3;a++){ + // Hashmapcell = new Hashmap<>(); + // for(int b=a;b Loop is running row wise + HashMaprow = new HashMap<>(); // ---> made a Hashmap for the row + HashMapcolumn = new HashMap<>(); // ---> made a Hashmap for the column + for(int j = 0;j Loop is running column wise + if ((row.containsKey(board[i][j]))&&((board[i][j]!='.'))){ + return false; + } + else{ + row.put(board[i][j],0); + } + if ((column.containsKey(board[j][i]))&&(board[j][i]!='.')){ + return false; + } + else{ + column.put(board[j][i],0); + } + + } + for(int a =i;a<3;a++){ + HashMapcell = new HashMap<>(); + for(int b=a;b Input: board = +//[["5","3",".",".","7",".",".",".","."] +//,["6",".",".","1","9","5",".",".","."] +//,[".","9","8",".",".",".",".","6","."] +//,["8",".",".",".","6",".",".",".","3"] +//,["4",".",".","8",".","3",".",".","1"] +//,["7",".",".",".","2",".",".",".","6"] +//,[".","6",".",".",".",".","2","8","."] +//,[".",".",".","4","1","9",".",".","5"] +//,[".",".",".",".","8",".",".","7","9"]] +//Output: true + +// Test case 2 ---> Input: board = +//[["8","3",".",".","7",".",".",".","."] +//,["6",".",".","1","9","5",".",".","."] +//,[".","9","8",".",".",".",".","6","."] +//,["8",".",".",".","6",".",".",".","3"] +//,["4",".",".","8",".","3",".",".","1"] +//,["7",".",".",".","2",".",".",".","6"] +//,[".","6",".",".",".",".","2","8","."] +//,[".",".",".","4","1","9",".",".","5"] +//,[".",".",".",".","8",".",".","7","9"]] +//Output: false + + +// ---> Question is to check if the Sudoku board is valid or not +// Points to check +// Each row must contain the digits 1-9 without repetition. +//Each column must contain the digits 1-9 without repetition. +//Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition. + + +// test case failing +//[[".",".",".",".","5",".",".","1","."], +// [".","4",".","3",".",".",".",".","."], +// [".",".",".",".",".","3",".",".","1"], +// ["8",".",".",".",".",".",".","2","."], +// [".",".","2",".","7",".",".",".","."], +// [".","1","5",".",".",".",".",".","."], +// [".",".",".",".",".","2",".",".","."], +// [".","2",".","9",".",".",".",".","."], +// [".",".","4",".",".",".",".",".","."]] \ No newline at end of file diff --git a/out/production/OpenSourceForAll/Main.class b/out/production/OpenSourceForAll/Main.class index fa0c590efb8a69455b301a755c6dcda734cc1046..977dbe120a73bad49d11009a18d93fa251337062 100644 GIT binary patch delta 266 zcmYL^u}%U(5Qe|GTW+~yML`fm1&&H=2nmT6NKIp_HHj9NTp%&_HoO4A7tul!3m<@| z;R%ehP`JtblbL__o7tsVn#Sh$`v+$5G0!Q9QV`D*y~N=jXa_!A(0jA}!x zfo9QMxcWlgcXm_N+i0Asy8Q)OoM{zv&V_dTo+IcL`#zmSVHUr3XmvR z04rcMh-V|j6!*@%cjmmAnVJ6Q_xlGhU@szIC1jPgChHL!bS#^eEg?A0iflR*8v6$q z<=5lTVQE^n9Xsp_?sSyrliuazF29K_T}O{tFlT922(58?pC)-)+$QH&hn