Skip to main content
All Questions

Given a fully or partially attempted 9x9 Sudoku board, determine if it is a valid solution.

Medium
Unlock detailed company stats for this questionUpgrade

Determine whether a partly filled 9 x 9 Sudoku board is valid so far. Only the filled cells need to follow the rules:

  • Each row contains the digits 1 to 9 at most once.
  • Each column contains the digits 1 to 9 at most once.
  • Each of the nine 3 x 3 boxes contains the digits 1 to 9 at most once.

Empty cells are written as ".". A valid board doesn't have to be solvable: you're only checking the digits already on it.

Example 1

Input: board = . . . . . . 7 . . . . 6 . 8 . . 2 3 7 . . 1 . 3 . 5 6 . 3 4 . . 7 . . . 5 . . . . 1 . 3 4 8 9 . 2 . 4 5 . . 3 . . 6 . 8 . . 2 . . . 9 1 2 . 4 . . . 2 . . . 6 . . Output: true

No digit repeats in any row, column or box.

Example 2

Input: board = . . . . 9 . . . . . . . . . . . . . . . . . . . . . . . 7 . . 2 . 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Output: false

The fourth row has two 7s.

Constraints

  • board has 9 rows and 9 columns.
  • Each cell is a digit from 1 to 9 or ".".

Related courses

Course

Engineering Management Interview Prep

Land your dream engineering manager role at Meta, Google, Amazon, Microsoft, Stripe, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates. Explore system design, people management, project retros, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.