14 · Hashing & Prefix Sums

#36 Valid Sudoku

Mediumsolve on LeetCode ↗

frequently reported atAppleUberAmazonMicrosoft

the problem

In plain words

Decide whether a partially filled 9×9 Sudoku board is valid: no digit 1–9 repeats in any row, any column, or any of the nine 3×3 boxes. Empty cells are '.'. The board need not be solvable.

in board = ["53..7....","6..195...",".98....6.","8...6...3","4..8.3..1","7...2...6",".6....28.","...419..5","....8..79"] (each string is one row)

out true

in The same board, but the first row is "83..7...."

out false

Two 8s in the top-left box.

  • board is 9×9
  • board[i][j] is a digit 1–9 or '.'

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #217
      Contains Duplicate
      Easyin Hashing
    2. #51
      N-Queens
      Hardin Backtracking