Sudoku Solver 4x4 - aloalgo

Sudoku Solver 4x4

Medium

Write a program to solve a 4x4 Sudoku puzzle. The input board is a 4x4 grid of integers, where 0 represents an empty cell. Your goal is to fill the empty cells such that the following rules are satisfied:

  1. Each row must contain the digits 1-4 exactly once.
  2. Each column must contain the digits 1-4 exactly once.
  3. Each of the four 2x2 subgrids (also called "boxes") must contain the digits 1-4 exactly once.

The program should modify the input board in-place and return the solved board. You can assume that the given input board will have a unique solution.

Example 1

Input
[
  [0, 2, 3, 0],
  [3, 0, 0, 2],
  [2, 0, 0, 3],
  [0, 3, 2, 0]
]
Output
[
  [1, 2, 3, 4],
  [3, 4, 1, 2],
  [2, 1, 4, 3],
  [4, 3, 2, 1]
]
Explanation:

The empty cells are filled to satisfy all Sudoku rules for 4x4. For example, board[0][0] must be 1 to satisfy row, column, and 2x2 box rules.

Example 2

Input
[
  [0, 0, 0, 0],
  [0, 0, 0, 0],
  [0, 0, 0, 0],
  [0, 0, 0, 0]
]
Output
[
  [1, 2, 3, 4],
  [3, 4, 1, 2],
  [2, 1, 4, 3],
  [4, 3, 2, 1]
]
Explanation:

A completely empty board is solved to one possible valid 4x4 Sudoku solution.

Loading...
Input
[
  [0, 2, 3, 0],
  [3, 0, 0, 2],
  [2, 0, 0, 3],
  [0, 3, 2, 0]
]
Output
[
  [1, 2, 3, 4],
  [3, 4, 1, 2],
  [2, 1, 4, 3],
  [4, 3, 2, 1]
]

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!