Validate a NumPlace puzzle board to ensure it follows the core rules: each row, column, and block contains unique digits. This tests your ability to use data structures for efficient constraint validation, a common pattern in problem-solving.
You are given a partially filled NumPlace puzzle board represented as a 2D array (list of lists) of integers. The board is N x N, where N is a perfect square (e.g., 4x4, 9x9, 16x16). Some cells are filled with digits from 1 to N, while empty cells are represented by 0. Determine whether the current state of the board is valid according to the following rules: Each row must contain the digits 1 to N without repetition. Each column must contain the digits 1 to N without repetition. Each sqrt(N) x sqrt(N) subgrid (block) must contain the digits 1 to N without repetition. A board is considered invalid if ANY of these rules are broken. You do NOT need to solve the puzzle, only validate its current state.
Imagine manually checking a completed puzzle. The brute-force approach is like taking each number on the board and comparing it to every other number in its row, column, and block. If you find a duplicate, the board is invalid. This involves nested loops to check each cell against all other relevant cells.
Work through this problem with AI coaching and get real-time feedback
Practice This Problem