id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
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 ...
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 ...
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 ...
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 {\n static constexpr std::array<char, 10> kOptions = {'.', '1', '2', '3', '4', '5',\n '6', '7', '8', '9'};\n\n bool ValidRow(const vector<vector<char>>& board, int row) {\n std::unordered_set<char> char_set;\n for (int 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": "class Solution {\n static constexpr std::array<char, 10> kOptions = {'.', '1', '2', '3', '4', '5',\n '6', '7', '8', '9'};\n\n bool ValidRow(const vector<vector<char>>& board, int row) {\n std::unordered_set<char> char_set;\n for (int 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": "class Solution {\n static constexpr std::array<char, 10> kOptions = {'.', '1', '2', '3', '4', '5',\n '6', '7', '8', '9'};\n\n bool ValidRow(const vector<vector<char>>& board, int row) {\n std::unordered_set<char> char_set;\n for (int 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": "class Solution {\npublic:\n vector<int>row;\n vector<int>col;\n vector<int>block;\n Solution() : row(9, 0), col(9, 0), block(9, 0) {}\n void SudokuUtil(vector<vector<char>>& board, vector<vector<int>>cells, int idx, int n, bool &complete){\n if(idx==n){\n complete=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\n const int countBits(const uint16_t val) const\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 // if a cell has a value defined, remove it from all ot...
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 pair<int,int> next_pos(pair<int,int> pos)\n {\n int x = pos.first;\n int y = pos.second;\n\n if(y<8)\n return {x,y+1};\n return {x+1,0};\n }\n\n bool row_ok(vector<vector<char>>& board, int x)\n {\n vector<bool> vis(...
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 = 32; // 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\n const int countBits(const uint16_t val) const\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 // if a cell has a value defined, remove it from all ot...
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 const int countBits(const uint16_t val) const\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 // if a cell has a value defined, remove it from all ot...
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 const int countBits(const uint16_t val) const\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 // if a cell has a value defined, remove it from all ot...
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<char>> trymat(queue<pair<int,int>> blanks,vector<vector<char>> board,vector<vector<int>> vert,vector<vector<int>> hor, vector<vector<int>> squares){\n\n // cout << \"hor\"<<endl;\n // for(int i =0; i <board.size();i++){\n // for(int j...
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 const int countBits(const uint16_t val) const\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 // if a cell has a value defined, remove it from all ot...
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 store(vector<vector<char>>& board, char ch, unordered_set<int>& row, unordered_set<int>& col, unordered_set<int>& block) {\n for (int i = 0; i < 9; i++) {\n for (int j = 0; j < 9; j++) {\n if (board[i][j] == ch) {\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 const int countBits(const uint16_t val) const\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 // if a cell has a value defined, remove it from all ot...
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 store(vector<vector<char>>& sud, char ch, unordered_set<int>& row, unordered_set<int>& col, unordered_set<int>& block) {\n for (int i = 0; i < 9; i++) {\n for (int j = 0; j < 9; j++) {\n if (sud[i][j] == ch) {\n // stor...
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 store(vector<vector<char>>& board, char ch, unordered_set<int>& row, unordered_set<int>& col, unordered_set<int>& block) {\n for (int i = 0; i < 9; i++) {\n for (int j = 0; j < 9; j++) {\n if (board[i][j] == ch) {\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 const int countBits(const uint16_t val) const\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 // if a cell has a value defined, remove it from all ot...
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 bool isValidSudoku(vector<vector<char>>& board, int row, int col) {\n unordered_map<char, int> map;\n map.clear();\n for (int j = 0; j < 9; j++) {\n if (board[row][j] == '.') continue;\n if (map[board[row][j]] == 1) 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 void solveSudoku(vector<vector<char>>& board) {\n int totalDots = 0;\n for(int i=0;i<9;i++) {\n for(int j=0;j<9;j++) {\n if(board[i][j] == '.') {\n totalDots++;\n }\n }\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": "struct coord{\n size_t r;\n size_t c;\n};\n\nclass Solution {\npublic:\n\n bool validate(vector<vector<char>>& board, size_t r, size_t c){\n unordered_set<int> seen;\n for(size_t i = 0; i < 9; i++){\n if(board[r][i] == '.' || seen.find(board[r][i]) == seen.end()){\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": "struct coord{\n size_t r;\n size_t c;\n};\n\nclass Solution {\npublic:\n\n bool validate(vector<vector<char>>& board, size_t r, size_t c){\n unordered_set<int> seen;\n for(size_t i = 0; i < 9; i++){\n if(board[r][i] == '.' || seen.find(board[r][i]) == seen.end()){\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 f=0;\n void func(vector<vector<char>>& v,vector<vector<bool>> row,vector<vector<bool>> col,vector<vector<vector<bool>>> box,vector<vector<char>> vv,int ind){\n if(ind==81){\n f=1;\n v=vv;\n return;\n }\n int i,j,k;\...
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 f=0;\n void func(vector<vector<char>>& v,vector<vector<bool>> row,vector<vector<bool>> col,vector<vector<vector<bool>>> box,vector<vector<char>> vv,int ind){\n if(ind==81){\n f=1;\n v=vv;\n return;\n }\n int i,j,k;\...
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 full(vector<vector<char>>& board)\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 return false;\n }\n }\n return true;\n }\n bool is...
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 bool ok=false;\n vector<vector<char>>ans;\n bool row_check(int r,vector<vector<char>>&v){\n map<char,int>m;\n for(int i=0;i<9;i++){\n if(v[r][i]!='.'){\n m[v[r][i]]++;\n if(m[v[r][i]]>1)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 int mxIndex=-1;\n void solveSudoku(vector<vector<char>>& board) {\n vector<pair<int,int>> slots;\n int n = board.size();\n int m = board[0].size();\n for(int i = 0;i<n;i++){\n for(int j =0;j<m;j++){\n if(board[i][j]=='....
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 bool isValid(vector<vector<char>>& board, int i, int j){\n unordered_set<char>rows, cols, block;\n for(int k=0; k<9; k++){\n if(board[i][k]!='.'){\n if(rows.find(board[i][k])!= rows.end()) return false;\n rows.insert(bo...
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 // TODO read board and save all empty cells to the queue\n std::deque<Cell> empties;\n for (int row = 0; row < 9; ++row) {\n for (int col = 0; col < 9; ++col) {\n if (board[row][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": "class Solution {\npublic:\n void solveSudoku(vector<vector<char>>& board) {\n //try to fill vertically if you can\n solve(board);\n\n }\n bool checkColumn(const std::vector<std::vector<char>>& board, int colIdx, char val) {\n set<char> seen;\n for (int i = 0; i < 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 void solveSudoku(vector<vector<char>>& board) {\n\n solve(board);\n\n }\n bool checkColumn(const std::vector<std::vector<char>>& board, int colIdx, char val) {\n set<char> seen;\n for (int i = 0; i < board.size(); i++) {\n if (board[i][co...
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": "struct coord{\n size_t r;\n size_t c;\n};\n\nclass Solution {\npublic:\n\n bool check_sudoku(vector<vector<char>>& board, size_t r, size_t c){\n unordered_set<char> nums = {'1','2','3','4','5','6','7','8','9'};\n\n for(size_t i = 0; i < 9; i++){\n if(board[r][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": "struct coord{\n size_t r;\n size_t c;\n};\n\nclass Solution {\npublic:\n\n bool check_sudoku(vector<vector<char>>& board, size_t r, size_t c){\n unordered_set<char> nums = {'1','2','3','4','5','6','7','8','9'};\n\n for(size_t i = 0; i < 9; i++){\n if(board[r][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": "struct coord{\n size_t r;\n size_t c;\n};\n\nclass Solution {\npublic:\n\n bool check_sudoku(vector<vector<char>>& board, size_t r, size_t c){\n unordered_set<char> nums = {'1','2','3','4','5','6','7','8','9'};\n\n for(size_t i = 0; i < 9; i++){\n if(board[r][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 // 判断是否合法(valid)\n bool is_valid(vector<vector<char>>& board) { // 虽然代码很长但是其实很好写\n for(int i=0;i<9;i++) {\n vector<int> vis(9);\n for(int j=0;j<9;j++) {\n if(board[i][j]=='.') continue;\n if(vis[board[i][j]-'1'])...
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 // 判断是否合法(valid)\n bool is_valid(vector<vector<char>>& board) { // 虽然代码很长但是其实很好写\n for(int i=0;i<9;i++) {\n vector<int> vis(9);\n for(int j=0;j<9;j++) {\n if(board[i][j]=='.') continue;\n if(vis[board[i][j]-'1'])...
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 // 判断是否合法(valid)\n bool is_valid(vector<vector<char>>& board) { // 虽然代码很长但是其实很好写\n for(int i=0;i<9;i++) {\n vector<int> vis(9);\n for(int j=0;j<9;j++) {\n if(board[i][j]=='.') continue;\n if(vis[board[i][j]-'1'])...
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 print(vector<vector<char>>& board){\n for(int i=0;i<9;i++){\n for(int j=0;j<9;j++){\n cout<<board[i][j]<<\" \";\n }\n cout<<endl;\n } \n }\n void solveSudoku(vector<vector<char>>& board) {\n he...
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 isAnswer = false;\n void backtracking(vector<vector<char>>& board, vector<vector<bool>> row, vector<vector<bool>> col, vector<set<int>> squares, int srow) {\n for (int i = srow; i < 9; i++) {\n for (int j = 0; j < 9; j++) {\n if (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 isAnswer = false;\n void backtracking(vector<vector<char>>& board, vector<vector<bool>> row, vector<vector<bool>> col, vector<set<int>> squares, int srow) {\n for (int i = srow; i < 9; i++) {\n for (int j = 0; j < 9; j++) {\n if (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 isValid(vector<vector<char>> board, int row, int col, char c)\n {\n int n = board.size();\n for (int i = 0; i < n; i++)\n {\n if(board[row][i] == c) return false;\n if(board[i][col] == c) return false;\n if (board[...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
0
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if (n == 1) return \"1\";\n string prevStr = \"1\";\n n--;\n string currStr = \"\";\n while (n)\n {\n int count = 0;\n char prev = '0';\n char currDigit;\n // b...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
0
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n string temp=\"1\", ans=\"\";\n for(int i=2;i<=n;i++){\n ans=\"\";\n for(int j=0;j<temp.size();j++){\n int count=1;\n char ch=temp[j];\n while(j<temp.size()-1 && temp...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
0
{ "code": "class Solution {\n\n void addDigit(string & res, size_t count) {\n while (count != 0) {\n res.push_back(count % 10 + '0');\n count /= 10;\n }\n }\n string countAndSayCore(string lastRes, int currN) {\n if (currN == 0) return lastRes;\n else {\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
0
{ "code": "class Solution {\n\npublic:\n\n string countAndSay(int n) {\n\n if(n==1){\n\n return \"1\";\n\n }\n\n string t=countAndSay(n-1);\n\n vector<char> a;\n\n for(int i=t.size()-1;i>=0;i--){\n\n a.push_back(t[i]);\n\n }\n\n string s;\n\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
2
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n == 1)\n return \"1\";\n \n \n string say = countAndSay(n-1);\n \n string result = \"\";\n \n // Just count and store in result and return\n for(int i = 0; i<say.length...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
2
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if (n == 1)\n return \"1\";\n string s = countAndSay(n - 1);\n string ans = \"\", a;\n int count = 0;\n char pres;\n for (int i = 0; i < s.size(); i++) {\n if (i == 0) {\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n==1) return \"1\";\n string str = countAndSay(n-1);\n vector<pair<int,int>> counter;\n int i=0;\n int m = str.length();\n while(i<m){\n int j = i;\n while(j<m && str[i]==str[j]) ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string RLE(const string& org) {\n int cnt = 0;\n vector<char> chars;\n vector<int> cnts;\n\n for (int i = 0; i < org.length(); i++) {\n if (chars.empty() || chars.back() != org[i]) {\n chars.push_back(org[i]);\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string crunch(const string& num) {\n vector<int> digits;\n\n for (char c : num) {\n digits.push_back(c - '0');\n }\n\n int prev = digits[0];\n int count = 1;\n vector<int> ans;\n\n for (int i = 1; i < digits.size() +...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string crunch(const string& num) {\n vector<int> digits;\n\n for (char c : num) {\n digits.push_back(c - '0');\n }\n\n int prev = digits[0];\n int count = 1;\n vector<int> ans;\n\n for (int i = 1; i < digits.size() +...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if (n == 1) {\n return \"1\";\n }\n else {\n string res{};\n stack<string> s;\n auto prev = countAndSay(n-1);\n int idx = prev.size()-1;\n\n while (idx > -1) ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if (n==1) return \"1\";\n\n string s = countAndSay(n-1);\n map<char,int> hashMap; \n char prev_c = s[0];\n string output_string = \"\";\n int idx = 0;\n while (idx<s.length()){\n char c ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string solve(string s, int &times, int t){\n times++;\n vector<pair<string,char>>v;\n int n=s.length(), i=0;\n while(i<n){\n int cnt=0;\n char cur_char=s[i];\n while(i<n && s[i]==cur_char){\n i++;\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n string result;\n if(n==1){\n return \"1\";\n }else{\n string previous = countAndSay(n - 1); \n vector<vector<int>> pairs = mapsToPair(previous); \n return pairToInt(pairs); \n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n string ans=\"1\";\n if(n == 1)\n return ans;\n for(int i=2;i<=n;i++)\n {\n vector<vector<string>> feq;\n for(int j=0;j<ans.size();j++)\n {\n int count=1;\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n vector<pair<string, char>> string_to_pair(string a){\n vector<pair<string, char>> arr; \n char c = a[0];\n int f = 1;\n for(int i=1; i<a.length(); i++){\n if(a[i]==c) f++;\n else{\n arr.push_back(make_pair(to_st...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n void helper(string& num,int n){\n if(n==1){\n return ;\n }\n vector<vector<int>> freq;\n for(int i=0;i<num.length();i++){\n vector<int> arr;\n int count=0;\n int ele=num[i];\n while(num[i]==ele...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n vector<vector<char>> createPairs(string s) {\n char ch = s[0];\n int count = 0;\n int i = 1;\n vector<vector<char>> g;\n\n for (int i = 0; i < s.size();) {\n \n char f = s[i];\n ch = s[i];\n count ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\n vector<vector<int>> hlp1(string sn){\n vector<vector<int>> d;\n d.clear();\n char prv = sn[0];\n int cnt = 0;\n for(char x : sn){\n if(x == prv){\n cnt++; continue;\n }\n vector<int> tmp = {prv - '0',cn...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\n static void initialize() {\n static bool initialized = false;\n if (!initialized) {\n basic();\n initialized = true;\n }\n }\n static vector<string> ret;\n static void basic() {\n ret = vector<string>(51);\n ret[1] = \"...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n //base cases\n if(n == 1){\n return \"1\";\n }\n string newString = countAndSay(n-1);\n string returnString = \"\";\n int i=0;\n int j=0;\n while(j < newString.length()){\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n //base cases\n if(n == 1){\n return \"1\";\n }\n string newString = countAndSay(n-1);\n string returnString = \"\";\n int i=0;\n int j=0;\n while(j < newString.length()){\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n int d;\n vector<string> harsh;\n harsh.push_back(\"1\");\n harsh.push_back(\"11\");\n harsh.push_back(\"21\");\n harsh.push_back(\"1211\");\n string ishu;\n\n for(int i = 4; i <35; i++) { // Only generate up to the nt...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution { \n public: \n void st_to_array(string st,int num_, unordered_map<int,vector<vector<int>>>&res){\n int i=0; \n vector<vector<int>> tmp;\n\n std::cout<<st<<std::endl;\n while(i<st.size()){ \n int count=1; \n int num=st[i++]-48; \n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n==0) return \"\";\n std::string str {\"1\"};\n for(auto i { 1 }; i < n; i++) {\n std::string temp {\"\"};\n for(auto j { 0 }; j < str.size();) {\n auto end_seq { str.substr(j).find_fir...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\nprivate:\n string getRunLengthEncoding(string digitString) {\n string encodedString = \"\";\n while(!digitString.empty()) {\n int numConsecutiveChars = 1;\n while(numConsecutiveChars < digitString.length() && digitString[numConsecutiveChars] == digit...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\nprivate:\n string getRunLengthEncoding(string digitString) {\n string encodedString;\n \n while(!digitString.empty()) {\n int numConsecutiveChars = 1;\n while(numConsecutiveChars < digitString.length() && digitString[numConsecutiveChars] == digitS...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if (n == 1) {\n return \"1\";\n }\n\n string s = countAndSay(n - 1);\n string ans = \"\";\n int cnt = 1;\n while (s.length() > 0) {\n char current = s[0];\n for (int i = 1...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if (n == 1) {\n return \"1\";\n }\n\n string s = countAndSay(n - 1);\n string ans = \"\";\n int cnt = 1;\n while (s.length() > 0) {\n char current = s[0];\n for (int i = 1...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n==1) return \"1\";\n\n vector<int> ans = {1};\n vector<int> v = {1};\n\n int i=1;\n while(i<n){\n v = ans;\n ans.clear();\n int j=0;\n\n while(j<v.size()){\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n vector<int> ans;\n vector<int> temp;\n temp.push_back(1);\n\n int count = 1;\n int ele = 1;\n int i = 0;\n int j = 0;\n while (i < n - 1) {\n ele = temp[0];\n count = 1...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n==1) return \"1\";\n\n vector<int> ans = {1};\n vector<int> v = {1};\n\n int i=1;\n while(i<n){\n v = ans;\n ans.clear();\n int j=0;\n\n while(j<v.size()){\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n==1)return \"1\";\n string s=countAndSay(n-1);\n string p=\"\";\n long long c=1;\n for(int i=1;i<s.size();i++){\n if(s[i]==s[i-1]){\n c++;\n }\n else{\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n vector<int> update(vector<int> v){{\n\n vector<int> ans;\n for(int i=0;i<v.size();i++){\n int count = 1;\n int j=i+1;\n while(j<v.size()){\n if(v[j] == v[i]){\n count++;\n j++;...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n \n vector<pair<int,int>> compress(queue<int> nums)\n {\n int count = 0;\n int prev = -1;\n vector<pair<int,int>> compressed;\n while(!nums.empty())\n {\n if(nums.front() == prev)\n {\n ++count;\...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n \n vector<pair<int,int>> compress(queue<int> nums)\n {\n int count = 0;\n int prev = -1;\n vector<pair<int,int>> compressed;\n while(!nums.empty())\n {\n if(nums.front() == prev)\n {\n ++count;\...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n string ans=\"1\";\n n--;\n while(n--)\n {\n string curr=\"\";\n int nn=ans.size();\n int k=0;\n for(int i=0;i<nn;i=k)\n {\n int ct=1;\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n string ans=\"1\";\n n--;\n while(n--)\n {\n string curr=\"\";\n int nn=ans.size();\n int k=0;\n for(int i=0;i<nn;i=k)\n {\n int ct=1;\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n string str = \"1\";\n if(n==1)return str;\n\n string st = \"\";\n string stt = \"\";\n for(int i = 1;i<n;i++)\n {\n int index = 0;\n int count = 1;\n while(index < str.len...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n==1) return \"1\";\n if(n==2) return \"11\";\n string res = \"\";\n int prev=-1;\n int counter = 1;\n string num = \"11\";\n for(size_t i=2;i<n;i++)\n {\n int prev_num=-1, fig...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n stack<char>st;\n char t='1';\n //string temp=\"1\";\n st.push(t);\n if(n==1)return \"1\";\n string temp=\"\";\n for(int i=1;i<n;i++){\n int count=0;\n temp=\"\";\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string cas(int n, string result){\n if(n==1)\n return \"1\";\n\n string str = cas(n-1, result);\n int m = str.size();\n\n int i=0;\n while(i<m){\n char ch = str[i];\n int count = 0;\n while(i<m && ch==...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n\n string helper(int n)\n {\n if(n==1)\n {\n return \"1\";\n }\n else\n {\n string ans = helper(n-1);\n //return ans\n // map<char,int>freq;\n vector<pair<char,int>>freq;\n f...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string p=\"\";\n\n string rle(string a){\n stack<pair<int,char>> s;\n for(char c:a){\n if(s.size() and s.top().second==c){\n int tmp=s.top().first;\n s.pop();\n s.push({++tmp,c});\n }\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n string ret = \"\";\n if(n!= 1){\n ret = countAndSay(n-1);\n }\n\n if(ret.length() == 0)\n ret = to_string(1);\n else{\n stack<int> num;\n stac...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n string ret = \"\";\n if(n!= 1){\n ret = countAndSay(n-1);\n }\n\n if(ret.length() == 0)\n ret = to_string(1);\n else{\n stack<int> num;\n stac...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n static vector<string> cached_ans;\n if(!cached_ans.size()){\n cached_ans.resize(30);\n cached_ans[0] = \"1\";\n string old, ans;\n for(int num = 1; num < 30; num++){\n old =...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n int getTimesOfChar(string s, int &index) {\n char ch = s[index];\n int count = 0;\n while(index < s.size() && s[index] == ch) {\n index++;\n count++;\n }\n\n return count;\n }\n string countAndSay(int n) {\n ...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "string RLE(string s) {\n stack<pair<char, int>> st;\n string ans = \"\";\n int counter;\n\n// s = \"312211\";\n for(int i=0; i<s.size(); i++){\n counter = 1;\n\n for(int j=i+1; j<s.size(); j++) { \n if(s[i] == s[j]) counter++; else break;\n } \n\n st.push(ma...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n==1){return \"1\";}\n else if(n==5){return \"111221\";}\n else if(n==10){return \"13211311123113112211\";}\n else if(n==15){return \"311311222113111231131112132112311321322112111312211312111322212311322113212221\";...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n==1){return \"1\";}\n else if(n==5){return \"111221\";}\n else if(n==10){return \"13211311123113112211\";}\n else if(n==15){return \"311311222113111231131112132112311321322112111312211312111322212311322113212221\";...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n if(n==1){return \"1\";}\n else if(n==10){return \"13211311123113112211\";}\n else if(n==30){return \"3113112221131112311332111213122112311311123112111331121113122112132113121113222112311311221112131221123113112221121113311211...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string rle(string s)\n {\n if (s.length() == 0)\n return \"\";\n for (int i = 1; i < s.length(); i++)\n {\n if (s[i] != s[0])\n return rle(s.substr(0, i)) + rle(s.substr(i, s.length() - i));\n }\n retu...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n string result = \"\";\n for(int i = 1; i <= n; i++){\n if(i == 1){\n result = \"1\";\n }\n else{\n result = solve(result);\n }\n }\n return resu...
38
<p>The <strong>count-and-say</strong> sequence is a sequence of digit strings defined by the recursive formula:</p> <ul> <li><code>countAndSay(1) = &quot;1&quot;</code></li> <li><code>countAndSay(n)</code> is the run-length encoding of <code>countAndSay(n - 1)</code>.</li> </ul> <p><a href="http://en.wikipedia.org/...
3
{ "code": "class Solution {\npublic:\n string countAndSay(int n) {\n string result = \"\";\n for(int i = 1; i <= n; i++){\n if(i == 1){\n result = \"1\";\n }\n else{\n result = solve(result);\n }\n }\n return resu...