Skip to content

Bug Report for valid-sudoku #4068

Closed
Closed
@Brentably

Description

@Brentably

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions