-
Notifications
You must be signed in to change notification settings - Fork 75
Open
Labels
Description
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_sudokufolder 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
trueif the board is valid, andfalseotherwise - 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.
Reactions are currently unavailable