0% found this document useful (0 votes)
19 views

Hash Solution

The code sample shows a binary search algorithm to find a target value in a sorted array. It also shows a method to validate if a Sudoku board representation is valid by checking for duplicate values within each row, column, and 3x3 sub-box.

Uploaded by

adfadfad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Hash Solution

The code sample shows a binary search algorithm to find a target value in a sorted array. It also shows a method to validate if a Sudoku board representation is valid by checking for duplicate values within each row, column, and 3x3 sub-box.

Uploaded by

adfadfad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

int left = 0;

int right = arr.length - 1;


while (left < right) {
int mid = left + (right - left) / 2;
if (arr[mid] < target) {
left = mid + 1;
} else {
right = mid;
}
}
public static boolean isValidSudoku_array(char[][] board) {
int[][] row = new int[9][9];
int[][] col = new int[9][9];
int[][][] subBox = new int[3][3][9];
for (int subIdx = 0; subIdx < 9; subIdx++) {
int subRow = 3 * (subIdx / 3);
int subCol = 3 * (subIdx % 3);
Set<Integer> grpSet = new HashSet<>();
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
char ch = board[subRow + i][subCol + j];
if (ch != '.') {
int num = ch - '0';
if (!grpSet.add(num)) {
return false;
}
}
}
}
}

return true;
}

You might also like