| 75 | }; |
| 76 | |
| 77 | var searchGrid = (board, boxes, cols, rows) => { |
| 78 | const [_rows, _cols] = [9, 9]; |
| 79 | |
| 80 | for (let row = 0; row < _rows; row++) { |
| 81 | /* Time O(ROWS)*/ |
| 82 | for (let col = 0; col < _cols; col++) { |
| 83 | /* Time O(COLS)*/ |
| 84 | const char = board[row][col]; |
| 85 | const index = Math.floor(row / 3) * 3 + Math.floor(col / 3); |
| 86 | |
| 87 | const isEmpty = char === '.'; |
| 88 | if (isEmpty) continue; |
| 89 | |
| 90 | const hasMoved = |
| 91 | boxes[index][char - 1] || |
| 92 | cols[col][char - 1] || |
| 93 | rows[row][char - 1]; |
| 94 | if (hasMoved) return false; |
| 95 | |
| 96 | rows[row][char - 1] = true; /* Space O(ROWS * COLS)*/ |
| 97 | cols[col][char - 1] = true; /* Space O(ROWS * COLS)*/ |
| 98 | boxes[index][char - 1] = true; /* Space O(ROWS * COLS)*/ |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | return true; |
| 103 | }; |
| 104 | |
| 105 | /** |
| 106 | * Array - Fixed Size |