id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 1 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n char valueH,valueV,value;\n for (int i = 0; i < 9; i++) {\n unordered_set<char> horizontal;\n unordered_set<char> vertical;\n\n\n for (int j = 0; j < 9; j++) {\n\n valueH = board[i][j];\n... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n int gridStart = 0;\n for(int i=0;i<9;i++)\n {\n //sub box start position\n int start = 27*(i/3)+(i%3*3);\n unordered_set<char> row;\n unordered_set<char> col;\... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "#include <vector>\n#include <unordered_set>\nusing namespace std;\n\nclass Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n // Iterate over each row, column, and box\n for (int i = 0; i < 9; ++i) {\n unordered_set<char> rowSet;\n unordered_set... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool check(vector<char> &v) {\n set<char> s;\n for(int i = 0; i < v.size(); i++) {\n if(v[i] == '.') continue;\n if(v[i] < '0' || v[i] > '9') {\n return false;\n }\n if(s.find(v[i]) != s.end()) {\n re... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) \n {\n for (int i = 0; i < board.size(); i++)\n {\n unordered_map<char, int> foundH;\n unordered_map<char, int> foundV;\n for (int j = 0; j < board.size(); j++)\n {\n ... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n for(int i=0; i<9; i++){\n unordered_map<char, int>mp;\n for(int j=0; j<9; j++){\n if(board[i][j]!='.' && mp[board[i][j]]) return false;\n mp[board[i][j]]++;\n ... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) \n {\n for (int i = 0; i < board.size(); i++)\n {\n unordered_map<char, int> foundH;\n unordered_map<char, int> foundV;\n for (int j = 0; j < board.size(); j++)\n {\n ... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n for(int i=0; i<9; i++){\n unordered_map<char, int>mp;\n for(int j=0; j<9; j++){\n if(board[i][j]!='.' && mp[board[i][j]]) return false;\n mp[board[i][j]]++;\n ... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool Traversal(vector<vector<char>>&board,int sr,int er,int sc,int ec){ \n unordered_set<char> st;\n for(int row =sr; row<=er; row++){\n for(int col =sc;col<=ec ;col++){\n if(board[row][col]=='.') continue;\n if(st.find(b... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n map<pair<int,int>,map<int,int>>mp;\n vector<map<int,int>>row(9);\n vector<map<int,int>>col(9);\n for(int i=0;i<9;i++){\n for(int j=0;j<9;j++){\n if(board[i][j]!='.'){\n ... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "\n\nclass Solution {\npublic:\n bool validBox(vector<vector<char>>& board, int sr, int er, int sc, int ec) {\n unordered_set<char> st;\n for (int i = sr; i <= er; i++) {\n for (int j = sc; j <= ec; j++) {\n if (board[i][j] == '.') continue;\n if (st... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n vector<unordered_map<char,bool>> boxes(9);\n\n //rows check\n for(int r=0 ; r < 9 ; r++){\n unordered_map<char,bool> rows;\n for(int c= 0 ; c < 9 ; c++){\n if(board[r... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n // Check each row\n for (int i = 0; i < 9; i++) {\n if (!isValidRows(board[i])) {\n return false;\n }\n }\n\n // Check each column\n for (int i = 0; i <... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n\n\n bool isValidSudoku(vector<vector<char>>& board) {\n map<char,int>mp;\n map<char,int>mp1;\n map<char,int>mp2;\n for(int i=0;i<board.size();i++){\n // rows\n mp.clear();\n for(int j=0;j<board[0].size();j++){\n ... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\nbool checkRow(vector<vector<char>> board)\n{\n for(int i=0;i<board.size();i++)\n {\n vector<int> numbers(10,1);\n for(int j=0;j<board[i].size();j++)\n {\n if(board[i][j]!='.')\n numbers[board[i][j]-'0']--;\n }\n f... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n int n = 9;\n int m = 9;\n\n // check cols\n for (int x = 0; x < n; x++) {\n unordered_set<char> nums;\n for (int y = 0; y < m; y++) {\n if (board[y][x] == '.')... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n vector<vector<int>> rows;\n vector<int> empty9;\n vector<vector<int>> columns;\n vector<vector<int>> boxes;\n for(int i = 0;i<9;i++){\n empty9.push_back(0);\n }\n f... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n // the size of the board\n int row = board.size();\n int column = board[0].size();\n\n // scan different rows\n unordered_map<char, int> row_mp1;\n for (int i = 0; i < column; i++) {... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n int m = board.size();\n int n = board[0].size();\n \n //validate rows\n for(int i = 0; i < m; i++){\n unordered_set<char> set;\n for(int j = 0; j<n; j++){\n ... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n int N = 9;\n unordered_set<char> rows[N];\n unordered_set<char> cols[N];\n unordered_set<char> boxes[N];\n\n for(int r = 0; r < N; r++) {\n for(int c= 0; c< N; c++) {\n ... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n unordered_set<string> check;\n for(int i = 0; i < 9; i++) {\n for(int j = 0; j < 9; j++) {\n if(board[i][j] == '.') {\n continue;\n }\n ... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n //maybe we need lots of hash sets? I feel like this is wrong though\n //ohhhh to initialize an array of rows we can just do rows[9]\n int length = board[0].size()-1;\n unordered_set<char> rowSet[9... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n unordered_set<char> rows[9];\n unordered_set<char> cols[9];\n unordered_set<char> boxes[9];\n\n for (int r = 0; r < 9; ++r) {\n for (int c = 0; c < 9; ++c) {\n if (board[... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n unordered_set<char> rows[9];\n unordered_set<char> cols[9];\n unordered_set<char> boxes[9];\n\n for (int r = 0; r < 9; ++r) {\n for (int c = 0; c < 9; ++c) {\n if (board[... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n vector<unordered_set<char>> rows(9);\n vector<unordered_set<char>> cols(9);\n vector<unordered_set<char>> boxes(9);\n \n for (int i=0; i<board.size(); i++) {\n for (int j=0; j<bo... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n unordered_set<char> rows[9];\n unordered_set<char> cols[9];\n unordered_set<char> boxes[9];\n\n for (int r = 0; r < 9; ++r) {\n for (int c = 0; c < 9; ++c) {\n if (board[... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n vector<unordered_set<char>> rows(9);\n vector<unordered_set<char>> cols(9);\n vector<unordered_set<char>> boxes(9);\n for(int i=0;i<9;i++)\n {\n for(int j=0;j<9;j++)\n ... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 2 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n unordered_set<char> rows[9];\n unordered_set<char> cols[9];\n unordered_set<char> boxes[9];\n\n for (int r = 0; r < 9; ++r) {\n for (int c = 0; c < 9; ++c) {\n if (board[... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 3 | {
"code": "class Solution {\n\n public:\n\n bool isValidSudoku(vector<vector<char>>& board) {\n\n unordered_set<string> seen;\n\n for (int i = 0; i < 9; ++i)\n\n for (int j = 0; j < 9; ++j) {\n\n if (board[i][j] == '.')\n\n continue;\n\n const string c(1, board[i][j]);\n\n if... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 3 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n unordered_set<char> rows[9];\n unordered_set<char> cols[9];\n unordered_set<char> boxes[9];\n\n for (int r = 0; r < 9; ++r) {\n for (int c = 0; c < 9; ++c) {\n if (board[... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 3 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n vector<unordered_set<int>> rowSet(9, unordered_set<int>()), colSet(9, unordered_set<int>()), gridSet(9, unordered_set<int>());\n for(int i = 0; i < 9; i++){\n for(int j = 0; j < 9; j++){\n ... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 3 | {
"code": "class Solution {\n public:\n bool isValidSudoku(vector<vector<char>>& board) {\n unordered_set<string> seen;\n\n for (int i = 0; i < 9; ++i)\n for (int j = 0; j < 9; ++j) {\n if (board[i][j] == '.')\n continue;\n const string c(1, board[i][j]);\n if (!seen.insert(c... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 3 | {
"code": "class Solution {\n\n public:\n\n bool isValidSudoku(vector<vector<char>>& board) {\n\n unordered_set<string> seen;\n\n for (int i = 0; i < 9; ++i)\n\n for (int j = 0; j < 9; ++j) {\n\n if (board[i][j] == '.')\n\n continue;\n\n const string c(1, board[i][j]);\n\n if... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 3 | {
"code": "class Solution {\n public:\n bool isValidSudoku(vector<vector<char>>& board) {\n unordered_set<string> seen;\n\n for (int i = 0; i < 9; ++i)\n for (int j = 0; j < 9; ++j) {\n if (board[i][j] == '.')\n continue;\n const string c(1, board[i][j]);\n if (!seen.insert(c... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 3 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n unordered_map<int,unordered_map<int,int>>r,c,b;\n int cnt=0;\n for(int i=0;i<9;i++)\n {\n for(int j=0;j<9;j++)\n {\n if(board[i][j]=='.')continue;\n ... |
36 | <p>Determine if a <code>9 x 9</code> Sudoku board is valid. Only the filled cells need to be validated <strong>according to the following rules</strong>:</p>
<ol>
<li>Each row must contain the digits <code>1-9</code> without repetition.</li>
<li>Each column must contain the digits&... | 3 | {
"code": "class Solution {\npublic:\n bool isValidSudoku(vector<vector<char>>& board) {\n vector<unordered_set<int>> row(9);\n vector<unordered_set<int>> col(9);\n vector<vector<unordered_set<int>>> box(3, vector<unordered_set<int>>(3));\n for(int i = 0; i<9; i++){\n for(int... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 0 | {
"code": "class Solution {\n bool isSafe(vector<vector<char>>&board,int num,int x,int y){\n char e=(char)num+'0';\n for(int i=0;i<9;i++){\n if(board[x][i]==e || board[i][y]==e){\n return 0;\n }\n }\n int a=(x/3)*3;\n int b=(y/3)*3;\n f... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 0 | {
"code": "class Solution {\npublic:\n bool isSafe(int row,int col,vector<vector<char>>&board,char val){\n for(int i=0;i<9;i++){\n if(board[row][i]==val){\n return false;\n }\n if(board[i][col]==val){\n return false;\n }\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n bool HasItem(vector<char> &v, char item) {\n auto it = find(v.begin(), v.end(), item);\n if (it != v.end()) return true;\n return false;\n }\n void RemoveItem(vector<char> &v, char k) {\n auto it = find(v.begin(), v.end(), k);\n if (it... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n bool HasItem(vector<char> &v, char item) {\n auto it = find(v.begin(), v.end(), item);\n if (it != v.end()) return true;\n return false;\n }\n void RemoveItem(vector<char> &v, char k) {\n auto it = find(v.begin(), v.end(), k);\n if (it... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "typedef std::pair<int, int> loc;\n\nnamespace std\n{\n template<class A,class B>\n struct hash<pair<A,B>>{\n size_t operator() (const pair<A,B>& p) const {\n return hash<A>{}(p.first) << 1 ^ hash<B>{}(p.second);\n }\n };\n}\n\nclass Solution {\n const std::array<char, 9... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "typedef std::pair<int, int> loc;\n\nnamespace std\n{\n template<class A,class B>\n struct hash<pair<A,B>>{\n size_t operator() (const pair<A,B>& p) const {\n return hash<A>{}(p.first) << 1 ^ hash<B>{}(p.second);\n }\n };\n}\n\nclass Solution {\n const std::array<char, 9... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n\n\n bool solve(vector<vector<char>>& board,vector<vector<unordered_set<int>>> &subset,vector<unordered_set<int>> &row,vector<unordered_set<int>> &col,int r, int n){\n\n for(int j=0;j<n;++j){\n if(board[r][j]=='.'){\n for(int i=1;i<=n;++i){\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n\n\n bool solve(vector<vector<char>>& board,vector<vector<unordered_set<int>>> &subset,vector<unordered_set<int>> &row,vector<unordered_set<int>> &col,int r, int n){\n\n for(int j=0;j<n;++j){\n if(board[r][j]=='.'){\n for(int i=1;i<=n;++i){\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n unordered_set<string> getCurrentSudokuStatus(vector<vector<char>>& board) {\n int n = board.size();\n unordered_set<string> st;\n for (int row = 0; row < n; row++)\n {\n for (int col = 0; col < n; col++)\n {\n i... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n void solveSudoku(vector<vector<char>>& board) {\n row_cache = vector<set<char>>(board.size(), set<char>());\n col_cache = vector<set<char>>(board.size(), set<char>());\n sq_cache = vector<set<char>>(board.size(), set<char>());\n\n for (int i = 0; ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n using Pos = pair<int, int>;\n // fill in each empty cell with possible digits\n // possible digits could be determined by current board\n // i.e. current line, current column and current subbox\n // if all cells are filled, return result and stop traversing\n /... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n void displayBoard(const vector<vector<char>>& B)\n {\n for (int i = 0; i < 9; ++i)\n {\n for (int j = 0; j < 9; ++j)\n {\n cout << B[i][j] << ' ';\n }\n cout << '\\n';\n }\n cout << '\\n... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n\nbool isValid(vector < vector < char >> & board, int row, int col, int c) {\n for (int i = 0; i < 9; i++) {\n if (board[i][col] == char('0'+c))\n return false;\n\n if (board[row][i] == char('0'+c))\n return false;\n\n // if (board[3 * (row / 3) + i / 3][3 * (... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n vector<int> getNext(int i, int j){\n if(j == 8){\n i++;\n j = 0;\n }\n else{\n j++;\n }\n return {i, j};\n }\n bool isValid(vector<vector<char>> &board, int i, int j, int x){\n char ch = x + '0';... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "#include <iostream>\n#include <random>\n#include <array>\n#include <vector>\n#include <string>\n#include <map>\n#include <unordered_map>\n#include <set>\n#include <unordered_set>\n#include <algorithm>\n#include <functional>\n#include <queue>\n#include <stack>\n#include <bitset>\n\n#include <math.h>\n\nusin... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\n void dfs( vector<pair<int,int>> i, vector<vector<int>> &cl, vector<vector<int>> &ro, vector<vector<int>> &sq, int ind, vector<int> &v) {\n if(ind==i.size()) {\n return;\n }\n else {\n int j = i[ind].first;\n int k= i[ind].second;\n... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n vector<int> rowMoves = {0, 0, -1, 1};\n vector<int> colMoves = {1, -1, 0, 0};\n bool valid = false;\n void solveSudoku(vector<vector<char>>& board) {\n int n = 0;\n vector<pair<int, int>> positions;\n for(int i=0; i<board.size(); i++) {\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\nvoid solve(vector<vector<char>>& board, bool & ans, int row, int col){\n\nif(ans)\nreturn;\nif(row == 9){ans = true; return;}\n\nwhile(col < 9 && board[row][col] != '.'){col++;}\n\nif(col == 9){solve(board, ans, row+1, 0); return;}\n\nset<char> banned;\nfor(int i = 0; i < 9; i++)... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n bool solve(vector<vector<char>>&b, set<char>s){\n for(char i='1';i<='9';i++){\n s.insert(i);\n }\n for(int i=0;i<9;i++){\n for(int j=0;j<9;j++){\n if(b[i][j]=='.'){\n for(char O='1';O<='9';O++){\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n bool solve(vector<vector<char>>& board){\n\n int x=-1,y=-1;\n\n for(int i=0;i<9;i++){\n for(int j=0;j<9;j++){\n\n if(board[i][j] == '.'){\n x=i;y=j;\n break;\n }\n }\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n void solveSudoku(vector<vector<char>>& board) {\n solve(board, 0, 0);\n }\n\n bool solve(vector<vector<char>>& board, int row, int col) {\n\n if (row == board.size()) {\n return isValid(board);\n }\n\n if (board[row][col] != '.') {... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n void solveSudoku(vector<vector<char>>& board) {\n solve(board);\n }\n bool solve(std::vector<std::vector<char>>& board) {\n const std::string nums = \"123456789\";\n for (int i = 0;i < board.size(); ++i) {\n for (int j = 0;j < board.size(... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n vector<int> missing(vector<vector<char>> board, int x, int y){\n vector<bool> ava(10, true);\n int bi = x / 3;\n int bj = y / 3;\n \n for (int i = 3 * bi; i < 3 * (bi + 1); i++) {\n for (int j = 3 * bj; j < 3 * (bj + 1); j++) {\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n\n // vector<vector<int>> intsudoku(vector<vector<char>> board){\n // vector<vector<int>> sudoku(9, vector<int>(9, -1));\n // for (int i=0; i<9; i++)\n // { \n // for (int j=0; j<9; j++)\n // {\n // if (int (board[i]... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n class cell{\n public:\n int r;\n int c;\n cell(int row, int col) : r(row), c(col) {}\n };\n void solveSudoku(vector<vector<char>>& board) {\n int row=9,col=9;\n vector<int> rflag(9,0);\n vector<int> cflag(9,0)... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\nclass cell{\n public:\n int r;\n int c;\n cell(int row,int col):r(row),c(col){}\n};\n void solveSudoku(vector<vector<char>>& board) {\n vector<int> rflag(9,0);\n vector<int> cflag(9,0);\n vector<int> smflag(9,0);\n for(int i=0;i<9;i++){\... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n bool done = false;\n int block_num(int i , int j){\n if(i >= 0 && i <= 2){\n if(j >= 0 && j <= 2){\n return 0;\n }\n if(j >= 3 && j <= 5){\n return 1;\n }\n if(j >= 6 && j <= 8){\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n int block_num(int i , int j){\n if(i >= 0 && i <= 2){\n if(j >= 0 && j <= 2){\n return 0;\n }\n if(j >= 3 && j <= 5){\n return 1;\n }\n if(j >= 6 && j <= 8){\n return 2;... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\nint rol[9] = {0}, col[9] = {0}, rc3[9] = {0};\nint n = 9, m = 9, done = 0;\nvoid initial(vector<vector<char>> board)\n{\n for (int i = 0; i < n; ++i)\n {\n for (int j = 0; j < m; ++j)\n {\n if (!isdigit(board[i][j]))\n continue;\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\n void getOccuranceSet(vector<vector<char>>& board, int x, int y, unordered_set<char>& rowSet, unordered_set<char>& colSet, unordered_set<char>& matrixSet) {\n // get row set\n rowSet.clear();\n for (int j = 0; j < 9; j++) {\n if (board[x][j] == '.') {\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\nprotected:\n vector<bool> seen = vector(9, false);\n\n vector<int> getRemainingValues(const vector<vector<int> > &board, const int row, const int col) {\n ranges::fill(seen.begin(), seen.end(), false);\n\n // check box\n const int top = row / 3 * 3;\n const int bottom = top ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "constexpr int rowSkip = 9; // 9 best without aligning\nclass Solution {\npublic:\n\n inline\n const int countBits(const uint16_t val) const noexcept\n {\n int result = 0;\n constexpr uint16_t one = 1;\n for(int i=1;i<10;i++)\n result += (val>>i)&one;\n return... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n\n struct hashFunction \n { \n size_t operator()(const pair<bool, \n bool> &x) const\n { \n return x.first ^ x.second; \n } \n }; \n\n void f(unordered_set<pair<int,int>, hashFunction>&s, vector<vector<int>>&... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution{\n using compact = std::array<char, 81>;\n\n compact compactify(auto const& board) noexcept{\n compact result{};\n for (int i = 0; i < 9; i++)\n for (int j = 0; j < 9; j++)\n result[i * 9 + j] = board[i][j];\n return result;\n }\n\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution{\n using compact = std::array<char, 81>;\n\n compact compactify(auto const& board) noexcept{\n compact result{};\n for (int i = 0; i < 9; i++)\n for (int j = 0; j < 9; j++)\n result[i * 9 + j] = board[i][j];\n return result;\n }\n\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<char>> ans;\n bool isValid(int k,int i,int j,vector<vector<char>>&board,int n){\n char x = k+'0';\n for(int p=0;p<n;p++)if(board[i][p]==x)return false;\n for(int p=0;p<n;p++)if(board[p][j]==x)return false;\n int rowStart=i/3;\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<char>> ans;\n bool isValid(int k,int i,int j,vector<vector<char>>&board,int n){\n char x = k+'0';\n for(int p=0;p<n;p++)if(board[i][p]==x)return false;\n for(int p=0;p<n;p++)if(board[p][j]==x)return false;\n int rowStart=i/3;\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n bool backtracking(vector<vector<char>>& board, vector<vector<bool>>& rows, vector<vector<bool>> cols, vector<vector<bool>> boxs) {\n for (int i = 0; i < 9; ++i) {\n for (int j = 0; j < 9; ++j) {\n if (board[i][j] == '.') {\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<char>> ans;\n char a[10] ={'0','1','2','3','4','5','6','7','8','9'};\n bool check(vector<vector<char>> &board, int row , int col){\n for(int i = 0;i<9;i++){\n if(i!=row && board[i][col]==board[row][col]) return false;\n if(i!=c... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "constexpr int rowSkip = 14; // 9\nclass Solution {\npublic:\n\n inline\n const int countBits(const uint16_t val) const noexcept\n {\n int result = 0;\n constexpr uint16_t one = 1;\n for(int i=1;i<10;i++)\n result += (val>>i)&one;\n return result;\n }\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n void solveSudoku(vector<vector<char>>& board) {\n vector<vector<vector<int>>> boardVar(9, vector<vector<int> >(9, vector<int>(9)));\n for (int i = 0; i < 9; i++) {\n for (int j = 0; j < 9; j++) {\n if (board[i][j] == '.')\n board... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "constexpr int rowSkip = 15; // 9\nclass Solution {\npublic:\n\n inline\n const int countBits(const uint16_t val) const noexcept\n {\n int result = 0;\n constexpr uint16_t one = 1;\n for(int i=1;i<10;i++)\n result += (val>>i)&one;\n return result;\n }\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "bool isval(char ch,int row,int col,vector<vector<char>> &board){\n vector<int> a(10,0),b(10,0),c(10,0);\n board[row][col] = ch;\n \n for(int i=0;i<9;i++){\n if (board[i][col]!='.') a[board[i][col]-'1']++;\n if (board[row][i]!='.') b[board[row][i]-'1']++;\n // cout<<a[boar... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "bool isval(char ch,int row,int col,vector<vector<char>> &board){\n vector<int> a(10,0),b(10,0),c(10,0);\n board[row][col] = ch;\n \n for(int i=0;i<9;i++){\n if (board[i][col]!='.') a[board[i][col]-'1']++;\n if (board[row][i]!='.') b[board[row][i]-'1']++;\n // cout<<a[boar... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "constexpr int rowSkip = 16; // 9\nclass Solution {\npublic:\n\n inline\n const int countBits(const uint16_t val) const noexcept\n {\n int result = 0;\n constexpr uint16_t one = 1;\n for(int i=1;i<10;i++)\n result += (val>>i)&one;\n return result;\n }\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "constexpr int rowSkip = 16; // 9 best without aligning\nclass Solution {\npublic:\n\n inline\n const int countBits(const uint16_t val) const noexcept\n {\n int result = 0;\n constexpr uint16_t one = 1;\n for(int i=1;i<10;i++)\n result += (val>>i)&one;\n retur... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n void bf(vector<vector<char>> board,int n,vector<vector<char>>& ans){\n if(n == 0){\n ans = board;\n return;\n }\n \n for(int i{0};i<9;i++){\n for(int j{0};j<9;j++){\n if(board[i][j]=='.'){\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n void bf(vector<vector<char>> board,int n,vector<vector<char>>& ans){\n if(n == 0){\n ans = board;\n return;\n }\n \n for(int i{0};i<9;i++){\n for(int j{0};j<9;j++){\n if(board[i][j]=='.'){\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n\n\n bool solve(int cell,vector<vector<char>>& grid,vector<vector<int>>& rw,vector<vector<int>>& cl,vector<vector<vector<int>>> sqr){\n if(cell == 81) return true;\n int row = cell/9;\n int col = cell%9;\n if(grid[row][col] != '.') return solve(cell... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n void solveSudoku(vector<vector<char>>& board) {\n vector<set<int>> rows(9, set<int>()), cols(9, set<int>()), blocks(9, set<int>());\n\n backtrack(board, 0, 0, rows, cols, blocks);\n\n }\n\n bool backtrack(vector<vector<char>>& board, int row, int col, vect... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n void solveSudoku(vector<vector<char>>& board) {\n vector<set<int>> rows(9, set<int>()), cols(9, set<int>()), blocks(9, set<int>());\n\n backtrack(board, 0, 0, rows, cols, blocks);\n\n }\n\n bool backtrack(vector<vector<char>>& board, int row, int col, vect... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "#include <algorithm>\n#include <vector> \n#include <set>\n\nclass Solution {\npublic:\n bool findNextFreeCell(vector<vector<char>>& board, int prevR, int prevC, int& r, int& c) {\n bool found = false;\n int i, j;\n if (prevR == 8 && prevC ==8) {\n return false;\n }... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "#include <algorithm>\n#include <vector> \n#include <set>\n\nclass Solution {\npublic:\n bool findNextFreeCell(vector<vector<char>>& board, int prevR, int prevC, int& r, int& c) {\n bool found = false;\n int i, j;\n if (prevR == 8 && prevC ==8) {\n return false;\n }... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n //CHP SOLUTION (BACKTRACKING) - VERY BAD\n bool isAnswer = false;\n void backtracking(vector<vector<char>>& board, vector<vector<bool>> row, vector<vector<bool>> col, vector<vector<bool>> squares, int srow) {\n for (int i = srow; i < 9; i++) {\n for (i... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n void solveSudoku(vector<vector<char>>& board) {\n vector<vector<int>> res;\n for(int i = 0; i < 9; i++) {\n for(int j = 0; j < 9; j++) {\n if(board[i][j] == '.'){\n res.push_back({i, j});\n }\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\n inline void updatePossible(unordered_set<char> possible[9][9], int x, int y, int num)\n {\n for (int i = 0; i != 9; i++)\n {\n possible[x][i].erase(num);\n possible[i][y].erase(num);\n possible[x/3*3+i/3][y/3*3+i%3].erase(num);\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\n inline void updatePossible(unordered_set<char> possible[9][9], int x, int y, int num)\n {\n for (int i = 0; i != 9; i++)\n {\n possible[x][i].erase(num);\n possible[i][y].erase(num);\n possible[x/3*3+i/3][y/3*3+i%3].erase(num);\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "#include <vector>\n#include <queue>\n\nusing namespace std;\n\nclass Solution {\npublic:\n void solveSudoku(vector<vector<char>>& board) {\n bfsSolve(board);\n }\n\nprivate:\n // Helper function to check if placing 'val' at board[i][j] is valid\n bool isValid(vector<vector<char>>& board,... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n bool check(vector<vector<char>>& board) {\n for (int i = 0; i < 9; i++) {\n for (int j = 0; j < 9; j++) {\n if (board[i][j] == '.') {\n return false;\n }\n }\n }\n return true;\n }\... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n bool isValid(const vector<vector<char>>& board, int m, int n) {\n for (int i = 0; i < m; ++i) {\n vector<bool> seen(10);\n for (int j = 0; j < n; ++j) {\n if (board[i][j] != '.') {\n int num = board[i][j] - '0';\n... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n bool check(vector<vector<char>>& board) {\n for (int i =0; i < 9; i++) {\n vector<bool> cnt (9, false);\n for (int j = 0; j < 9; j++) {\n if (board[i][j] != '.') {\n if (cnt[board[i][j] - '1']) {\n ... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n static constexpr size_t sudokuSize = 9;\n\n using used_digits_t = std::bitset<9>;\n\n struct SudokuState {\n char UNSET_CELL = -1;\n\n array<used_digits_t, sudokuSize> rowsUsed;\n array<used_digits_t, sudokuSize> colsUsed;\n array<used_digits... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n static constexpr size_t sudokuSize = 9;\n\n using used_digits_t = std::bitset<9>;\n\n struct SudokuState {\n char UNSET_CELL = -1;\n\n array<used_digits_t, sudokuSize> rowsUsed;\n array<used_digits_t, sudokuSize> colsUsed;\n array<used_digits... |
37 | <p>Write a program to solve a Sudoku puzzle by filling the empty cells.</p>
<p>A sudoku solution must satisfy <strong>all of the following rules</strong>:</p>
<ol>
<li>Each of the digits <code>1-9</code> must occur exactly once in each row.</li>
<li>Each of the digits <code>1-9</code> must occur exactly once in eac... | 3 | {
"code": "class Solution {\npublic:\n\n /*\n void SolveUtil(vector<vector<char>>& board, vector<int>& row, vector<int>& col, vector<vector<int>>&grid, int i, int j)\n {\n if (i == board.size())\n {\n //cout<<\"i: \"<<i<<\" Size: \"<<board.size()<<endl;\n return;\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.