# LeetCode: Valid Sudoku Solution

## Implementation

```.css-ds3kc{display:table-row;}.css-1t8atru{display:table-cell;opacity:0.5;padding-right:var(--chakra-space-6);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;text-align:right;}1.css-2qghsv{display:table-cell;}function transpose(arrOfArr) {2  const N = arrOfArr.length3  const M = arrOfArr.length4  const res = []5  for (let i = 0; i < M; i++) {6    let temp = []7    for (let j = 0; j < N; j++) {8      temp.push(arrOfArr[j][i])9    }10    res.push(temp)11  }12  return res13}14
15function squareSizeOf3(arrOfArr) {16  const N = arrOfArr.length17  const M = arrOfArr.length18  const res = []19  for (let i = 0; i < N; i += 3) {20    for (let j = 0; j < M; j += 3) {21      let temp = []22      temp.push(arrOfArr[i].slice(j, j + 3))23      temp.push(arrOfArr[i + 1].slice(j, j + 3))24      temp.push(arrOfArr[i + 2].slice(j, j + 3))25      res.push(temp.flat())26    }27  }28  return res29}30
31/**32 * @param {character[][]} board33 * @return {boolean}34 */35var isValidSudoku = function (board) {36  return [...board, ...transpose(board), ...squareSizeOf3(board)]37    .map(row => row.filter(cell => cell !== "."))38    .every(row => row.length === new Set(row).size)39}```

Original problem

## Similar problems

Sudoku Solver

Check if Every Row and Column Contains All Numbers

leetcode

neetcode

array

hash table

## Next Post

LeetCode: Reverse String

Feb 5, 2021

Built-in string method

Search Posts