id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n if (original.size() != m * n) {\n return vector<vector<int>>();\n }\n vector<vector<int>> arr(original.size() / n);\n for (int i = 0; i < m; i++) {\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> result(m, vector<int>(n));\n if(original.size()!=n*m){\n return {};\n }\n int k=0;\n for(int i=0;i<m;i++){\n for(int j=0;...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n int count = 0;\n if(m*n!=original.size()){\n vector<vector<int>>nullarray;\n return nullarray;\n }\n vector<vector<int>>array(m);\n for(int i...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n\n vector<vector<int>> result(m, vector<int>(n,0));\n vector<vector<int>> emptyVec;\n\n if(original.size() != m*n) return emptyVec;\n\n int nTemp = 0;\n for(int i =...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> ans (m,vector<int> (n,0));\n if (m*n != original.size()) return {};\n\n for (int i = 0; i < original.size();i++) {\n int r = i / n;\n i...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> v(m,vector<int>(n));\n int x = original.size();\n if((m*n)!=x){\n for(int i=0;i<m;i++){\n v.pop_back();\n }\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n if (m * n != original.size()) {\n return {}; \n }\n\n std::vector<std::vector<int>> result(m, std::vector<int>(n));\n\n for(int num = 0; num < m ; num++ ){\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n std::vector<std::vector<int>> construct2DArray(std::vector<int>& original, int m, int n) {\n\n if (m * n != original.size()) {\n return {}; \n }\n\n std::vector<std::vector<int>> result(m, std::vector<int>(n));\n\n for (int i = 0; i < m;...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n // vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n\n // vector<vector<int>> result(m, vector<int>(n,0));\n // vector<vector<int>> emptyVec;\n\n // if(original.size() != m*n) return emptyVec;\n\n // // int nTemp = 0;\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n std::vector<std::vector<int>> construct2DArray(std::vector<int>& original, int m, int n) {\n\n if (m * n != original.size()) {\n return {}; \n }\n\n std::vector<std::vector<int>> result(m, std::vector<int>(n));\n\n for (int i = 0; i < m;...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> result(m,vector<int>(n));\n int col=0;\n if((m*n)!=original.size()) return {};\n vector<int>inner(n);\n for(int i=0;i<original.size();i++){\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) \n {\n if (m * n != original.size())\n return {};\n \n int** arr = new int*[m];\n for (int i=0; i<m; i++)\n arr[i]= new int[n];\n \n fo...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> ans(m, vector<int>(n));\n if(m*n<original.size()||m*n>original.size()) return {};\n if(m==1&&n==original.size()) return {original};\n for(int i=0;i<m;...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> res(m, vector<int>(n));\n int s = original.size();\n if (s != (m * n)) {\n return {};\n }\n if(m == 1)\n {\n retur...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);\n vector<vector<int>> res(m, vector<int>(n));\n int s = original.size();\n if (s != (m * n)) {\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> ans(original.size()/n);\n if(m*n!=original.size()){\n ans.resize(0);\n return ans;\n } \n for(int i = 0; i < m; i++){\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<int>::const_iterator it;\n vector<int>::const_iterator it_back;\n vector<vector<int>> res;\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n if (m * n != original.size()) {\n return res;\n }\n res.r...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<int>::const_iterator it;\n vector<vector<int>> res;\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n if (m * n != original.size()) {\n return res;\n }\n res.reserve(m);\n it = original.cbegin()...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> matrix(m);\n vector<vector<int>> empty;\n if (m * n != original.size()) {\n return empty;\n } \n int dummy_x = 0;\n for (int ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> v(m);\n int l = 0;\n if (n * m != original.size()){\n v.clear();\n return v;\n }\n for (int i=0;i<m;++i){\n ve...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>>ans(m);\n\n if(n*m<original.size() || n*m>original.size()){ vector<vector<int>>v;\n return v;\n }\n int row=0;\n int col = 0;\...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& o, int m, int n) {\n vector<vector<int>>mat(m);\n if(m*n!=o.size()) return {};\n int x=0,y=0;\n for(int i=0;i<o.size();i++){\n mat[x].push_back(o[i]);\n y++;\n if(y=...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>>res(m);\n if(size(original)>m*n || size(original)<m*n){\n vector<vector<int>>t;\n return t;\n }\n int i = 0;\n int c = 0;\...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>>res(m);\n if(size(original)>m*n || size(original)<m*n){\n vector<vector<int>>t;\n return t;\n }\n int i = 0;\n int c = 0;\...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n int len=original.size();\n vector<vector<int>>res;\n if(len!=m*n){\n return res;\n }\n int k=0;\n for(int i=0;i<m;i++){\n vector<int>r...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n if((m*n)!=original.size()){\n return {};\n }\n vector<vector<int>> res;\n int i=0;\n int b=original.size();\n while(i<b){\n vector<int...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n if (m * n != original.size()) return {};\n\n vector<vector<int>> output;\n\n int curr_idx = 0;\n\n for (int i = 0; i < m; ++i) {\n vector<int> inner(n);\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> nvec;\n if (m*n == original.size())\n {\n for (int i=0; i < m; i++){\n vector<int> row(original.begin()+(i * n) , original.begin()+ (i + 1) ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> out;\n if (original.size() != m*n) return out;\n\n for (int i = 0; i < m; i++) {\n out.emplace_back(vector<int>());\n for (int j = 0; j...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> vecvec;\n if(original.size() != m * n) {\n return vecvec;\n }\n for(int i=0; i<original.size(); ++i) {\n if(i % n == 0) {\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector <vector <int>> result;\nif (original.size() == m * n) {\n\tint i = 0;\n\n\twhile (m > 0) {\n\t\tresult.push_back({});\n\t\tfor (int j = n; j > 0; j--) {\n\n\t\t\tresult[result.size() -...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector <vector <int>> result;\nif (original.size() == m * n) {\n\tint i = 0;\n\n\twhile (m > 0) {\n\t\tresult.push_back({});\n\t\tfor (int j = n; j > 0; j--) {\n\n\t\t\tresult[result.size() -...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "\n#pragma GCC optimize (\"Ofast\")\n\nstatic vector<vector<int>> ans;\n\nclass Solution\n{\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n)\n {\n ans.clear();\n int l = int(original.size());\n if (l == (m * n))\n {\n int *p = ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "\n#pragma GCC optimize (\"Ofast\")\n\nstatic vector<vector<int>> ans;\n\nclass Solution\n{\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n)\n {\n ans.clear();\n int l = int(original.size());\n if (l == (m * n))\n {\n int *p = ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>>A(m,vector<int>(n));\n auto p=original;\n int x=p.size();\n if(x!=m*n) return vector<vector<int>>{};\n int h=0;\n for(int i=0;i<m;i++)\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& o, int m, int n) {\n \n vector<int>v;\n vector<vector<int>>ans;\n\n for(int i=0;i<o.size();i++)\n {\n v.push_back(o[i]);\n if(v.size()==n)\n {\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n int index = 0;\n vector<int> visited(original.size(),0);\n vector<vector<int>> twodArray(m,vector<int>(n,-1));\n for(int i = 0;i<m;i++){\n for(int j = 0;j<n;j+...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n int i=1,size=original.size();\n vector<vector<int>> ans;\n vector<int> row;\n while(i<=size){\n row.push_back(original[i-1]);\n if(m == 0) return ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>>Array;\n vector<int>vec;\n for(int i=0;i<original.size();i++){\n vec.push_back(original[i]);\n if(vec.size()==n)\n {\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<int>::const_iterator it;\n vector<int>::const_iterator it_back;\n vector<vector<int>> res;\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n if (m * n != original.size()) {\n return res;\n }\n //res...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<int>::const_iterator it;\n vector<int>::const_iterator it_back;\n vector<vector<int>> res;\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n if (m * n != original.size()) {\n return res;\n }\n it = ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n int k=original.size();\n if(k != (m*n)){\n return {};\n }\n vector<vector<int>> ans;\n vector<int> res;\n for(int i=0;i<k;i++){\n if((...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> result;\n if (original.size() != m*n) {\n return result;\n }\n\n // std::cout << result.size() << std::endl;\n vector<int>* nextRow;...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> arr {};\n\n if (m*n != original.size()) {\n return arr;\n }\n\n for (int i = 0; i < original.size(); i++) {\n int value = origin...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> result;\n for (int i = 0; i < m; i++) {\n result.push_back(vector<int>(n));\n }\n\n\n if (m*n != original.size()) { return {}; }\n\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> output(m,vector<int>(n));\n if(m*n != original.size()){\n return{};\n }\n for(int i = 0;i<m;i++){\n output[i] = vector<int>(...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n\n vector<vector<int>> result(m, vector<int>(n,0));\n vector<vector<int>> emptyVec;\n\n if(original.size() != m*n) return emptyVec;\n\n // int nTemp = 0;\n for(int ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n\n vector<vector<int>> result(m, vector<int>(n,0));\n vector<vector<int>> emptyVec;\n\n if(original.size() != m*n) return emptyVec;\n\n // int nTemp = 0;\n for(int ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n // simple conceptual problem\n int s=original.size();\n if(m*n!=s){\n return {};\n }\n vector<vector<int>>vec(m);\n for(int i=0;i<m;i++){\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> output(m,vector<int>(n));\n if(m*n != original.size()){\n return{};\n }\n for(int i = 0;i<m;i++){\n output[i] = vector<int>(...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> ans;\n vector<int> semians;\n int count=0;\n int size=0;\n if(original.size()==1)\n {\n if(m==1 && n==1){}\n else\...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n std::vector<std::vector<int>> construct2DArray(std::vector<int>& original, int m, int n) {\n std::vector<std::vector<int>> result = {};\n std::vector<int> tmp(n,0);\n for(int i = 0; i < m; ++i) result.push_back(tmp);\n\n if (n*m != original.size())...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> ans(m);\n int row = 0;\n for (int i = 0; i < original.size(); ++i) {\n if (i % n == 0 && i > 0) row++;\n if (row >= ans.size()) return ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n int s=original.size();\n if((m*n)!=s)return {};\n vector<vector<int>>ans(m,vector<int>(n));\n int k=0;\n for(int i=0;i<s;i+=n)\n {\n vector<int>v...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> ans(m);\n int h=original.size();\n int k=0;\n for(int i=0;i<m;i++){\n for(int j=0;j<n;j++){\n if(k==h)return {};\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n int s=original.size();\n if((m*n)!=s)return {};\n vector<vector<int>>ans(m,vector<int>(n));\n int k=0;\n for(int i=0;i<s;i+=n)\n {\n vector<int>v...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n //cout<<2*n-1;\n queue<int> q;\n int vSz = original.size();\n for(int i = 0;i<vSz;i++){\n q.push(original[i]);\n };\n int loop_length =2*n-2;\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> newvec;\n if (original.size()%n!=0){return {};}\n for (int i=n; i<=original.size();i+=n){\n vector<int> subvec(original.begin() + i-n, original.be...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> newvec;\n ios_base::sync_with_stdio(false);\n cin.tie(0); cout.tie(0);\n if (original.size()%n!=0){return {};}\n for (int i=n; i<=original.size...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> res(m, vector<int>(n, 0));\n vector<vector<int>> empty;\n\n int count = original.size();\n int k = 0;\n for (int i = 0; i < m; i++)\n {\...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> v(m, vector<int>(n));\n int count=0;\n int res = m*n;\n if(res!=original.size())\n {\n return {};\n }\n for(int i=0;i<...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> v(m, vector<int>(n));\n int count=0;\n int res = m*n;\n if(res!=original.size())\n {\n return {};\n }\n for(int i=0;i<...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> a;\n if (original.size()==m*n) {\n if (m==1) {\n a.push_back(original);\n } else {\n int k{0};\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n)\n {\n vector<vector<int>> rez = {};\n if(n*m != original.size())\n return rez;\n if(m == 1)\n {\n rez.push_back(original);\n return rez;\n...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> ans(m);\n int l = original.size();\n int j = 0;\n int i = 0;\n if(m*n != l) {\n ans.clear();\n return ans;\n }\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n if(m*n != original.size()){\n return {};\n }\n if(m==1){\n return{original};\n }\n vector<vector<int>> ans;\n for(int i=0; i<m; i++){\...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n \n vector<vector<int>> ans(m , vector<int>());\n\n int sz = original.size();\n\n if (sz!=m*n) return {};\n\n int i = 0;\n int j = 0;\n\n while (i<sz)...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& a, int m, int n) {\n vector<vector<int>> s(m, vector<int>(n)),s1;\n if(a.size() != n*m) return s1;\n else{\n vector<vector<int>> s(m, vector<int>(n));\n int k = 0;\n for(int i ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> a;\n if (original.size()==m*n) {\n for (int i=0; i<m; i++) {\n auto start=original.begin()+i*n;\n vector<int> r(n);\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> a;\n if (original.size()==m*n) {\n for (int i=0; i<m; i++) {\n auto start=original.begin()+i*n;\n vector<int> r(n);\n ...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>>A;\n int size=original.size();\n if(size!=(m*n))\n return A;\n\n for(int i=0;i<m;i++)\n {\n vector<int>temp;\n for(...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>>A;\n int size=original.size();\n if(size!=(m*n))\n return A;\n\n for(int i=0;i<m;i++)\n {\n vector<int>temp;\n for(...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {\n vector<vector<int>> matrix;\n int size= original.size();\n int x=0;\n if(m*n!=size) return matrix;\n for(int i=0;i<m;i++)\n {\n vector<int> nayi;...
2,132
<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>origi...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) \n {\n int Size = original.size();\n vector<vector<int>> Ans;\n if(m * n == Size)\n {\n for(auto i=0;i<m;++i)\n {\n int Left = i * n;\...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
0
{ "code": "class Solution {\npublic:\n bool isPossible(string &s, int len, int k){\n int f=0, t=0;\n for(int i=0;i<len;i++){\n f+=(s[i]=='F');\n t+=(s[i]=='T');\n }\n if(t<=k || f<=k) return true;\n int l=0, r=len-1;\n while(r!=s.size()-1){\n ...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
0
{ "code": "bool init = []() {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return true;\n}();\n\nclass Solution {\npublic:\n int maxConsecutiveAnswers(std::string_view answerKey, int k) {\n return std::max(solve(answerKey, k, 'T'), solve(answerKey, k, 'F'));\n }\...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
0
{ "code": "class Solution {\npublic:\n int helper(const string& s, int k, char ch)\n {\n int ans = 0, cnt = 0, i = 0, j = 0, n = s.size();\n while(j<n)\n {\n if(s[j++] != ch) cnt++;\n while(cnt > k) \n if(s[i++] != ch) cnt--;\n ans = max(ans, ...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
0
{ "code": "class Solution {\npublic:\n int maxConsecutiveAnswers(string answerKey, int k) \n {\n int trues=0, falses=0;\n int i=0, j=0, maxfreq=0;\n int maxlen=0;\n while(j<answerKey.length())\n {\n if(answerKey[j]=='T')\n {\n trues++;\n ...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
0
{ "code": "class Solution {\npublic:\n bool isWindowPossible(string &s, int window, int k) {\n int i = 0, j = window - 1;\n int t_count = 0, f_count = 0;\n \n for(int idx = 0; idx < window; idx++) {\n if(s[idx] == 'T') {\n t_count++;\n } else {\n ...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
0
{ "code": "class Solution {\npublic:\n int maxConsecutiveAnswers(string s, int k) {\n int ans = 0, n = s.length();\n int i=0, j=0, p=0;\n int maxlen=0;\n while(j<n){\n if(s[j]=='F') p++;\n while(p>k){\n if(s[i]=='F') p--;\n i++;\n ...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
0
{ "code": "class Solution {\npublic:\n int maxConsecutiveAnswers(string a, int k) {\n //case 1(f-t)\n int n=a.size();\n int result=0;\n int i=0,j=0;\n int countf=0;\n while(j<n){\n if(a[j]=='F')\n countf++;\n while(countf>k){\n ...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
0
{ "code": "class Solution {\npublic:\n int maxConsecutiveAnswers(string answerKey, int k) {\n int n = answerKey.size();\n int maxLen = 0;\n \n // Sliding window approach for both 'T' and 'F'\n for (char ch : {'T', 'F'}) {\n int left = 0, right = 0, changes = 0;\n ...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
1
{ "code": "class Solution {\npublic:\n int maxConsecutiveAnswers(string answerKey, int k) {\n vector<int>hash(2,0);\n int l=0,r=0,maxlen=0,maxfreq=0;\n while(r<answerKey.size()){\n if(answerKey[r]=='T'){\n hash[0]++;\n }\n if(answerKey[r]=='F'){\...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
1
{ "code": "class Solution {\npublic:\n // Helper function to calculate the maximum length with at most k changes\n int maxConsecutiveChar(string& answerKey, int k, char target) {\n int l = 0, maxlen = 0, changes = 0;\n \n for (int r = 0; r < answerKey.size(); ++r) {\n if (answerK...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
2
{ "code": "class Solution {\npublic:\n int maxConsecutiveAnswers(string answerKey, int k) {\n int maxi_one =0;\n int maxi_zero =0;\n int s1=0,e1=0,zero=0;\n int n = answerKey.length();\n string s = answerKey;\n while(e1<n)\n {\n if(s[e1]=='F') zero++;\n ...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
2
{ "code": "class Solution {\npublic:\n int maxConsecutiveAnswers(string answerKey, int k) {\n int left = 0, right = 0;\n map<char,int>mp;\n int n = answerKey.size();\n int maxi =0, maxf = 0;\n\n while(right < n){\n mp[answerKey[right]]++;\n maxf = max(maxf, ...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
2
{ "code": "class Solution {\npublic:\n int maxConsecutiveAnswers(string answerKey, int k) {\n int n=answerKey.size();\n int i=0;\n int maxi=0;\n int ans=0;\n unordered_map<char , int>mp;\n for(int j=0;j<n;j++){\n mp[answerKey[j]]++;\n maxi=max(maxi , ...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
2
{ "code": "class Solution {\npublic:\n int maxConsecutiveAnswers(string answerKey, int k) {\n int maxSize = 0;\n unordered_map<char, int> count;\n \n for (int right = 0; right < answerKey.length(); right++) {\n count[answerKey[right]]++;\n int minor = min(count['T'...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
2
{ "code": "class Solution {\npublic:\n int maxConsecutiveAnswers(string answerKey, int k) {\n unordered_map<char,int>mp;\n int n=answerKey.size();\n int i=0,j=0,res=0;\n int maxi=-1;\n while(j<n){\n mp[answerKey[j]]++;\n while(min(mp['T'],mp['F'])>k){\n ...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
3
{ "code": "class Solution {\npublic:\nint f(string s,char ch,int k){\n int ans=0,count=0,i=0,j=0,n=s.size();\n while(j<n){\n if(s[j]!=ch){\n count++;\n }\n while(count>k){\n if(s[i++]!=ch)count--;\n }\n ans=max(ans,j-i+1);\n j++;\n }\n return...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
3
{ "code": "class Solution {\npublic:\n\n int helper(string s, int k, char c){\n int ans=0,i=0,j=0,cnt=0,n=s.size();\n\n while(j<n){\n if(s[j]!=c) cnt++;\n\n while(cnt>k){\n if(s[i]!=c) cnt--;\n i++;\n }\n\n ans=max(ans,j-i+1);\...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
3
{ "code": "class Solution {\npublic:\n int help(string s,int k, char ch){\n int ans = 0,cnt = 0,i = 0,j = 0,n = s.size();\n while(j<n){\n if(s[j++]!=ch)cnt++;\n while(cnt>k)if(s[i++]!=ch)cnt--;\n ans = max(ans,j-i);\n }\n return ans;\n }\n int maxC...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
3
{ "code": "class Solution {\npublic:\n int helper(string s, int k, char ch) {\n int ans = 0, cnt = 0, i = 0, j = 0, n = s.size();\n while(j < n)\n {\n if(s[j++] != ch) cnt++;\n while(cnt > k) \n if(s[i++] != ch) cnt--;\n ans = max(ans, j-i);\n ...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
3
{ "code": "class Solution {\npublic:\n\n int helper(string s, int k, char c){\n int ans=0,i=0,j=0,cnt=0,n=s.size();\n\n while(j<n){\n if(s[j]!=c) cnt++;\n\n while(cnt>k){\n if(s[i]!=c) cnt--;\n i++;\n }\n\n ans=max(ans,j-i+1);\...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
3
{ "code": "class Solution {\npublic:\n int maxConsecutiveAnswers(string answerKey, int k) {\n std::ios_base::sync_with_stdio(false);\n \n return max(helper(answerKey, k, 'T'), helper(answerKey, k, 'F'));\n }\n int helper(string str, int k, char symbol) {\n int l = 0, r = 0;\n ...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
3
{ "code": "class Solution {\npublic:\n //same q as https://leetcode.com/problems/longest-repeating-character-replacement/\n int characterReplacement(string s, int k) {\n \n int n = s.length(), ans = 0;\n unordered_map<char, int> mp;\n\n int l=0, r=0;\n char max_char = 'A';\n ...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
3
{ "code": "class Solution {\npublic:\n int maxConsecutiveAnswers(string answerKey, int k) {\n deque<char> q;\n int n = answerKey.size();\n int ans = 0;\n for (int i=0; i<n; i++) {\n if (answerKey[i] == 'T') {\n q.push_back('T');\n } else {\n ...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
3
{ "code": "class Solution {\npublic:\n int maxConsecutiveAnswers(string ans, int k) \n {\n int n = ans.size(),fin=0;\n int left =1,right = n;\n vector<int>pre(n+1);\n \n \n\n while(left<=right)\n {\n int mid = (left+right)/2;\n int i=0,j=0;\n ...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
3
{ "code": "class Solution {\npublic:\n bool check(vector<int>& prefixSum, int k, int n, int m){\n if(m == 0){\n return true;\n }\n\n int nT = prefixSum[m - 1];\n int nF = m - nT;\n\n if(nT <= k || nF <= k)\n return true;\n\n for(int i = 1; i < n - m +...
2,134
<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>&#39;T&#39;</code> denoting true and <code>&#39;F&#39;</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the number of <strong>consecutive</strong> questions with the <strong>same</strong> answer (mu...
3
{ "code": "class Solution {\npublic:\n int solve(string st,char ch, int k){\n int i=0;\n int j=0;\n int n=st.length();\n int count=0;\n int ans=0;\n while(j<n){\n if(st[j]!=ch) count++;\n while(count>k){\n if(st[i]!=ch) count--;\n ...