Skip to content

[FEAT]: Valid Sudoku Implementation in Cairo #218

@coxmars

Description

@coxmars

Valid Sudoku Implementation in Cairo

📘 Description

Create an example that implements a solution to determine if a 9x9 Sudoku board is valid. This problem tests array manipulation, validation logic, and efficient checking algorithms - skills that are valuable for both interviews and practical programming.

✅ Acceptance Criteria

  • Create an exercises/valid_sudoku folder inside scripts folder and there create a scarb project as the other scripts.
  • Implement a function that determines if a 9x9 Sudoku board is valid according to these rules:
    • Each row must contain the digits 1-9 without repetition
    • Each column must contain the digits 1-9 without repetition
    • Each of the nine 3x3 sub-boxes of the grid must contain the digits 1-9 without repetition
  • The function should take a 9x9 board as input (can be represented as a 2D array)
  • Empty cells are represented with the character '.' (period)
  • The function should return true if the board is valid, and false otherwise
  • Include comprehensive test cases covering valid and invalid boards

📚 Examples

Example 1:

Input:

board = 
[["5","3",".",".","7",".",".",".","."]
,["6",".",".","1","9","5",".",".","."]
,[".","9","8",".",".",".",".","6","."]
,["8",".",".",".","6",".",".",".","3"]
,["4",".",".","8",".","3",".",".","1"]
,["7",".",".",".","2",".",".",".","6"]
,[".","6",".",".",".",".","2","8","."]
,[".",".",".","4","1","9",".",".","5"]
,[".",".",".",".","8",".",".","7","9"]]

Output: true
Explanation: This is a valid Sudoku board.

Example 2:

Input:

board = 
[["8","3",".",".","7",".",".",".","."]
,["6",".",".","1","9","5",".",".","."]
,[".","9","8",".",".",".",".","6","."]
,["8",".",".",".","6",".",".",".","3"]
,["4",".",".","8",".","3",".",".","1"]
,["7",".",".",".","2",".",".",".","6"]
,[".","6",".",".",".",".","2","8","."]
,[".",".",".","4","1","9",".",".","5"]
,[".",".",".",".","8",".",".","7","9"]]

Output: false
Explanation: The board is invalid because the first column contains two 8's.

🌎 References

📜 Additional Notes

  • ⚠ Read our guidelines before applying.
  • This is an intermediate exercise that tests array manipulation and efficient validation techniques.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions