Skip to content

Bug Report for valid-sudoku #4068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Brentably opened this issue Apr 22, 2025 · 1 comment
Open

Bug Report for valid-sudoku #4068

Brentably opened this issue Apr 22, 2025 · 1 comment

Comments

@Brentably
Copy link

Bug Report for https://neetcode.io/problems/valid-sudoku

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

Running this code:

class Solution {
    /**
     * @param {character[][]} board
     * @return {boolean}
     */
    isValidSudoku(board) {
        // create 9 + 9 + 9 lists
        const lists = []
        const boxes = []
        for(let i = 0; i < 9; i++) {
            const row = board[i]
            lists.push(row)
            const col = [] 
            // 9 boxes, 0,0, 0,1, 0,2 -- think of it as a 3x3 matrix
            for(let j = 0; i < 9; j++) { // technically a double for loop but capped at 9x9 operations
                col.push(board[i][j])
                console.log('test')
                let boxI = Math.floor(i / 3)
                if (boxI == 3) boxI = 2
                let boxJ = Math.floor(j / 3)
                if(boxJ == 3) boxJ = 2
                const boxesIndex = boxI * 3 + boxJ
                if(boxesIndex in boxes) {
                    boxes[boxesIndex].push(board[i][j])
                } else { 
                    boxes[boxesIndex] = [board[i][j]]
                }
            } 
            lists.push(col)
        }
        lists.push(...boxes)
        // console.log(lists)
        return true
        // for each list, create a set and itereate through to ensure no duplicates
    }

}

Getting this error:

Image
@Brentably
Copy link
Author

Noticed the bug here:
for(let j = 0; i < 9; j++) { // technically a double for loop but capped at 9x9 operations
because my second condition is i<9 instead of j<9, which causes it to just run forever.
-- that being said, stdout was not printing, which preventing me from debugging this, whereas on leetcode I was able to find this by printing. Maybe an improvement to be made?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant