FastPrepValid Sudoku
Problems/Valid Sudoku

Valid Sudoku

Microsoft logoMicrosoft● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a review of a Microsoft software engineering internship. The review lists the Valid Sudoku problem by name only, with no input or rules. The round is not named. The review describes two interviews that mixed coding and behavioral questions.

Here the board is nine strings of nine characters. Each is a digit 1 to 9 or a dot for an empty cell. Return true when no digit repeats in any row, column or 3 x 3 box. The board may be partly empty and does not have to be solvable.

Our version is about 95% the same as the reported question.

A 9 x 9 Sudoku board is given as nine strings. board[r][c] is the cell in row r and column c (both 0-based). Each cell holds a digit from 1 to 9, or '.' when it is empty.

The board is valid when, looking only at filled cells:

  • no row contains the same digit twice,
  • no column contains the same digit twice, and
  • none of the nine 3 x 3 boxes contains the same digit twice. The boxes are formed by rows 0-2, 3-5 and 6-8 crossed with columns 0-2, 3-5 and 6-8.

Return true if the board is valid and false otherwise. The board does not have to be full, and it does not have to be solvable: only repeated digits make it invalid.

Function

isValidSudoku(board: String[]) → boolean

Examples

Example 1

board = ["5..6..9..",".7..9..4.","..8..2..7","8..7..4..",".2..5..9.","..3..4..6","9..5..2..",".8..1..3.","..5..6..9"]return = true
board
01234567805..6..9..1.7..9..4.2..8..2..738..7..4..4.2..5..9.5..3..4..669..5..2..7.8..1..3.8..5..6..9

No digit appears twice in any row, any column or any of the nine 3 x 3 boxes, so the board is valid. Empty cells (.) are ignored.

Example 2

board = ["5.76..9..",".7..9..4.","..8..2..7","8..7..4..",".2..5..9.","..3..4..6","9..5..2..",".8..1..3.","..5..6..9"]return = false
board
01234567805.76..9..1.7..9..4.2..8..2..738..7..4..4.2..5..9.5..3..4..669..5..2..7.8..1..3.8..5..6..9

This is Example 1 with one more digit: a 7 at row 0, column 2 (0-based). Row 0 and column 2 still have no repeated digit, but the top-left box already has a 7 at row 1, column 1, so the board is not valid.

Constraints

  • board.length == 9 and board[i].length == 9
  • Every board[i][j] is a digit '1' to '9' or '.'.

More Microsoft Onsite Interview questions

  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
  • Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Sudoku Board ValidationConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
  • Validate Rectangular Game PiecesGoogle · ONSITE INTERVIEWGoogle interview questions
  • Query Whether an Island Size ExistsMeta · ONSITE INTERVIEWMeta interview questions
  • Validate a Sudoku BoardZipRecruiter · ONSITE INTERVIEWZipRecruiter interview questions
  • Check a Partly Filled Sudoku GridExpedia · ONSITE INTERVIEWExpedia interview questions
  • Cache Shared Image Pipeline PrefixesAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Sparse Matrix MultiplicationByteDance · PHONE SCREENByteDance interview questions
  • First Completed Mingo LineEpic · OAEpic interview questions
  • Valid SudokuVerkada · PHONE SCREENVerkada interview questions
  • Count 2x2 Submatrices by Black CellsTikTok · OATikTok interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public boolean isValidSudoku(String[] board) {
        // Write your code here.
    }
}
Checking account…