00:00

Problem Statement

Input/Output Examples

Visual Explanation

Filling cells in a fixed order (row by row) means both programs explore choices in the same order and therefore find the same solution.

Approaches

Both approaches use the same search order. One checks each digit by scanning; the other keeps bitmasks of used digits.

Java Solutions

Each tab is a complete program that runs on Java 17 or later. Both programs print the same output for the same inputs.

Complexity Analysis

Here e is the number of empty cells. The worst case is exponential, but constraint checks prune almost every branch, so typical puzzles solve in milliseconds.

Interview Tips and Recommended Approach

  • Compute the box index as (r / 3) * 3 + c / 3.
  • Always undo a placement before trying the next digit.
  • Mention a key speed-up: choose the empty cell with the fewest possible digits first.
  • Validate the input; a grid that breaks the rules from the start can never be solved.

Recommended Approach: Backtracking With Scans

Why: it is the most direct backtracking solution and is easy to verify, which is exactly what interviewers look for.