Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Validate Sudoku Correctness

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Validate Sudoku Correctness. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Samsara may receive structured diagnostic data from a Vehicle Gateway, where each record must satisfy strict validity rules before processing. Given a complete Sudoku grid, determine whether it is valid.

A grid is valid if every row, every column, and each of the nine 3x3 boxes contains every digit from 1 through 9 exactly once.

Formal Specification

Implement is_valid_sudoku(grid), where grid is a 9x9 list of lists containing integers. Return True when the grid satisfies all Sudoku rules, otherwise return False.

The grid is guaranteed to be complete and well-formed, so inputs contain only integers from 1 through 9 and always have exactly nine rows and nine columns.

Constraints

  • grid has exactly 9 rows
  • Each row has exactly 9 integers
  • 1 <= grid[row][col] <= 9
  • The grid is complete, with no empty cells

Function Signature

def is_valid_sudoku(grid):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output