Uber VO Coding Interview: Sudoku Validity Check

17 Views
No Comments

Sudoku is a number-placement puzzle. The objective is to fill a 9 x 9 grid with digits so that each column, each row, and each of the nine 3 x 3 sub-grids that compose the grid contains all of the digits from 1 to 9.

This algorithm should check if the given grid of numbers represents a correct solution to Sudoku.

Example

For the first example below, the output should be true. For the other grid, the output should be false: each of the nine 3 x 3 sub-grids should contain all of the digits from 1 to 9.

  • [execution time limit] 3 seconds (java)
  • [memory limit] 1 GB
  • [input] array.array.integer grid

A matrix representing 9 x 9 grid already filled with numbers from 1 to 9.

  • [output] boolean

true if the given grid represents a correct solution to Sudoku, false otherwise.

This problem asks you to verify whether a fully filled 9 x 9 Sudoku board is valid. The key is to check every row, every column, and every 3 x 3 sub-grid for duplicates and make sure each contains the digits 1 through 9 exactly once. A simple set-based or boolean-marking approach is enough, and a single pass over the board is typically sufficient.

END
 0