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..b25c717 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,11 +1,12 @@ + + - + - - + + + @@ -34,12 +42,16 @@ + + + @@ -51,23 +63,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 fa0c590..977dbe1 100644 Binary files a/out/production/OpenSourceForAll/Main.class and b/out/production/OpenSourceForAll/Main.class differ diff --git a/rotatedSortedArraySearch.java b/rotatedSortedArraySearch.java new file mode 100644 index 0000000..2c5cac7 --- /dev/null +++ b/rotatedSortedArraySearch.java @@ -0,0 +1,38 @@ +public class rotatedSortedArraySearch { + public static void main(String[] args) { + int[] a = {5, 6, 7, 8, 9, 1, 2, 3, 4}; + int l = a.length; + int c = checkSorted(a,l); + System.out.println(c); + + } + + public static int checkSorted(int[] a, int l) { + int target = 6; + int start = 0; + int end = l - 1; + int mid = 0; + while (start <= end) { + mid = (start + end) / 2; + if (a[mid]==target){ + return mid; + } + if (a[0] <= a[mid]) { + if ((a[0] <= target) && (a[mid] > target)) { + end = mid - 1; + } else { + start = mid + 1; + } + } else { + if ((a[mid] < target) && (a[end] >= target)) { + start = mid + 1; + } else { + end = mid - 1; + } + } + } + return -1; + + } +} +}