id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
118 | <p>Given an integer <code>numRows</code>, return the first numRows of <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAn... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> generate(int numRows) {\n // Initialize the result vector\n vector<vector<int>> result;\n\n // Generate each row of Pascal's Triangle\n for (int i = 0; i < numRows; ++i) {\n // Create a row with 1s\n vector<int> row(i + 1, 1);\n\n... |
118 | <p>Given an integer <code>numRows</code>, return the first numRows of <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAn... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> generate(int n) {\n vector<vector<int>> ans = {{1}};\n for(int i = 1; i < n; i++){\n vector<int> temp(i + 1, 1);\n for(int j = 1; j < i; j++){\n temp[j] = ans[i - 1][j] + ans[i - 1][j - 1];\n }... |
118 | <p>Given an integer <code>numRows</code>, return the first numRows of <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAn... | 0 | {
"code": "class Solution{\nprivate:\n void helper(int row, vector<int>& curr){\n curr.push_back(1);\n int res=1;\n for(int i=1; i<row; i++){\n res*=(row-i);\n res=res/i;\n curr.push_back(res);\n }\n }\n\npublic:\n vector<vector<int>> generate(int N){\n vector<vector<int>> res;\n f... |
118 | <p>Given an integer <code>numRows</code>, return the first numRows of <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAn... | 0 | {
"code": "class Solution {\npublic:\n vector<int>generateRow(int n){\n long long res=1;\n vector<int>ansRow;\n ansRow.push_back(1);\n for(int i=1;i<n;i++){\n res=res*(n-i);\n res=res/(i);\n ansRow.push_back(res);\n }\n return ansRow;\n ... |
118 | <p>Given an integer <code>numRows</code>, return the first numRows of <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAn... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> generate(int numRows) {\n vector<vector<int>> matrix(numRows);\n matrix[0].push_back({1});\n for (int i = 1; i < numRows; i++) {\n\n matrix[i].resize(i + 1); // this is the optimized approach\n\n for (int j = 0; j... |
118 | <p>Given an integer <code>numRows</code>, return the first numRows of <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAn... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> generate(int numRows) {\n vector<vector<int>> pascal(numRows);\n int c = 0;\n pascal[0].push_back(1);\n for(int i=1;i<numRows;i++){\n pascal[i].resize(i + 1);\n for(int j=0;j<=i;j++){\n if(j ... |
118 | <p>Given an integer <code>numRows</code>, return the first numRows of <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAn... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> generate(int numRows) {\n vector<vector<int>> result;\n\n for(int i=0; i<numRows; i++){\n vector<int> rows(i+1, 1);\n\n for(int j=1; j<i; j++){\n rows[j] = result[i-1][j-1] + result[i-1][j];\n }... |
118 | <p>Given an integer <code>numRows</code>, return the first numRows of <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAn... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> generate(int numRows) {\n vector<vector<int>> vp(numRows);\n vp[0] = {1};\n for(int i=1;i<numRows;i++){\n vp[i].push_back(1);\n\n for(int j=0;j<i-1;j++){\n vp[i].push_back(vp[i-1][j] + vp[i-1][j+1])... |
118 | <p>Given an integer <code>numRows</code>, return the first numRows of <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAn... | 2 | {
"code": "class Solution {\npublic:\n long long int fact(int k)\n {\n if(k==0)\n return 1;\n long long int ans=1;\n while(k>0)\n {\n ans*=k;\n k-=1;\n }\n return ans;\n }\n\n int comb(int n, int r)\n {\n int z=min(r,n-r... |
118 | <p>Given an integer <code>numRows</code>, return the first numRows of <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAn... | 2 | {
"code": "class Solution {\npublic:\n long long int fact(int k)\n {\n if(k==0)\n return 1;\n long long int ans=1;\n while(k>0)\n {\n ans*=k;\n k-=1;\n }\n return ans;\n }\n\n int comb(int n, int r)\n {\n int z=min(r,n-r... |
118 | <p>Given an integer <code>numRows</code>, return the first numRows of <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAn... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> generate(int numRows) {\n std::vector<std::vector<int>> res;\n res.push_back({1});\n\n for (int i = 0; i < numRows - 1; i++) {\n std::vector<int> dummyRow = {0};\n dummyRow.insert(dummyRow.end(), res.back().begin(... |
118 | <p>Given an integer <code>numRows</code>, return the first numRows of <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAn... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> generate(int numRows) {\n vector<int>prev={1};\n vector<int>curr={1,1};\n vector<vector<int>> sol;\n\n if(numRows==1){\n sol.push_back(prev);\n return sol;\n }\n if(numRows==2){\n s... |
118 | <p>Given an integer <code>numRows</code>, return the first numRows of <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAn... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> generate(int numRows) {\n std::vector<std::vector<int>> res;\n res.push_back({1});\n\n for (int i = 0; i < numRows - 1; i++) {\n std::vector<int> dummyRow = {0};\n dummyRow.insert(dummyRow.end(), res.back().begin(... |
118 | <p>Given an integer <code>numRows</code>, return the first numRows of <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAn... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> generate(int numRows) {\n std::vector<std::vector<int>> res;\n res.push_back({1});\n\n for (int i = 0; i < numRows - 1; i++) {\n std::vector<int> dummyRow = {0};\n dummyRow.insert(dummyRow.end(), res.back().begin(... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 0 | {
"code": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> getRow(int rowIndex) {\n vector<int> row(rowIndex + 1, 1); // Initialize all elements with 1\n \n // Compute the values in the row using the properties of Pascal's Triangle\n for (int i = 1; i ... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 0 | {
"code": "class Solution {\npublic:\n vector<int> getRow(int rows) {\n vector<int> ans(rows+1,1);\n \n for(int i=1;i<rows;i++)\n {\n \n for(int j=i;j>0;j--)\n {\n \n ans[j]+=ans[j-1];\n \n }\n ... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 0 | {
"code": "class Solution {\npublic:\n vector<int> getRow(int rowIndex) {\n \n long ans = 1;\n vector<int> ansRow;\n ansRow.push_back(ans);\n for(int i = 0; i<rowIndex; i++){\n ans *= (rowIndex-i);\n ans /= (i+1);\n ansRow.push_back(ans);\n ... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 0 | {
"code": "class Solution {\npublic:\nvector<int> rowgen(int row)\n{\n vector<int>rowal;\n long long sum=1;\n rowal.push_back(1);\n for(int i=1;i<=row;i++)\n {\n sum = sum * (row - i + 1) / i;\n rowal.push_back(sum); \n }\n return rowal;\n}\n vector<int> getRow(int rowIndex) {\n... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 0 | {
"code": "class Solution {\npublic:\n vector<int> getRow(int rowIndex) {\n vector<int> ans;\n int row=rowIndex;\n long long ans1=1;\n ans.push_back(ans1);\n \n for(int col=1;col<=row;col++)\n {\n ans1*=(row-col+1);\n ans1/=col;\n ans.p... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 0 | {
"code": "class Solution {\npublic:\n vector<int> getRow(int rowIndex) {\n int n = rowIndex+1;\n long long hello = 1;\n vector<int> ans;\n ans.push_back(hello);\n for(int i =1;i<n;i++){\n hello = hello*(n-i);\n hello = hello/i;\n ans.push_back(he... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 0 | {
"code": "class Solution {\npublic:\n vector<int> getRow(int rowIndex) {\n vector<int>a;\n vector<vector<int>>b;\n a.push_back(1);\n b.push_back(a);\n a.clear();\n int x1, x2;\n for(int i=1;i<=rowIndex;i++)\n {\n for(int j=0;j<=i;j++)\n ... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 0 | {
"code": "class Solution {\npublic:\n vector<int> getRow(int rowIndex) {\n vector<int> result(rowIndex + 1, 0);\n result[0] = 1;\n\n for (int row = 1; row <= rowIndex; ++row) {\n result[row] = 1;\n\n for (int index = row - 1; index > 0; --index) {\n result... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 0 | {
"code": "class Solution {\npublic:\n vector<int> getRow(int rowIndex) {\n vector<int> row(rowIndex + 1, 1); \n for (int i = 1; i < rowIndex; ++i) {\n for (int j = i; j > 0; --j) {\n row[j] = row[j] + row[j - 1];\n }\n }\n return row;\n }\n};\n",... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 0 | {
"code": "class Solution {\npublic:\n vector<int> getRow(int rowIndex) {\n vector<int> cur(rowIndex+1, 1), prev(rowIndex+1, 1);\n for(int i = 1; i <= rowIndex+1; i++){\n for(int j = 1; j < i-1; j++){\n cur[j] = prev[j-1]+prev[j];\n }\n prev = cur;\n ... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 1 | {
"code": "class Solution {\npublic:\n vector<int> getRow(int rowIndex) {\n int n = rowIndex + 1;\n vector<int> curr(n, 0), prev(n, 0);\n prev[0] = 1;\n for(int i= 2; i<= n; i++){\n for(int j = 0; j<i; j++){\n if(prev[j] == 0 || j - 1 < 0) curr[j] = 1;\n ... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 1 | {
"code": "class Solution {\npublic:\n vector<int> getRow(int rowIndex) {\n vector<int> result(rowIndex + 1, 0);\n result[0] = 1;\n\n for (int row = 1; row <= rowIndex; ++row) {\n result[row] = 1;\n\n for (int index = row - 1; index > 0; --index) {\n result... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 2 | {
"code": "class Solution {\npublic:\n vector<int> getRow(int rowIndex) {\n vector<vector<int>> result;\n\n for(int i=1; i<=rowIndex+1; i++){\n long ans = 1;\n vector<int> temp;\n temp.push_back(1);\n for(int j=1;j<i;j++){\n ans = ans * (i - ... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 2 | {
"code": "class Solution {\npublic:\n vector<int> getRow(int rowIndex) {\n vector<int>a;\n vector<vector<int>>b;\n a.push_back(1);\n b.push_back(a);\n a.clear();\n for(int i=1;i<=rowIndex;i++)\n {\n for(int j=0;j<=i;j++)\n {\n i... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 3 | {
"code": "class Solution {\npublic:\n vector<int> getRow(int rowIndex) {\n int size = 1;\n vector<vector<int>> pascal;\n vector<int> prev;\n while (size <= rowIndex + 1) {\n if (prev.size() == 0) {\n prev.push_back(1);\n }\n else {\n ... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 3 | {
"code": "class Solution {\npublic:\n vector<int> getRow(int rowIndex) {\n int size = 1;\n vector<vector<int>> pascal;\n vector<int> prev;\n while (size <= rowIndex + 1) {\n if (prev.size() == 0) {\n prev.push_back(1);\n }\n else {\n ... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 3 | {
"code": "class Solution {\npublic:\n vector<int> getRow(int rowIndex) {\n vector<vector<int>> result;\n\n for(int i=1; i<=rowIndex+1; i++){\n long ans = 1;\n vector<int> temp;\n temp.push_back(1);\n for(int j=1;j<i;j++){\n ans = ans * (i - ... |
119 | <p>Given an integer <code>rowIndex</code>, return the <code>rowIndex<sup>th</sup></code> (<strong>0-indexed</strong>) row of the <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://u... | 3 | {
"code": "class Solution {\npublic:\n vector<int> getRow(int rowIndex) {\n rowIndex++;\n std::vector<std::vector<int>> ans;\n ans.reserve(rowIndex);\n ans.push_back({1});\n\n for (int n = 2; n <= rowIndex; n++)\n {\n std::vector vec{1};\n for (int i ... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 0 | {
"code": "class Solution {\npublic:\n int minimumTotal(vector<vector<int>>& triangle) {\n int n = triangle.size();\n for (int i = n - 2; i >= 0; i--) {\n int row_size = triangle[i].size();\n for (int j = 0; j < row_size; j++) {\n triangle[i][j] += min(triangle[i... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 0 | {
"code": "class Solution {\npublic:\n int minimumTotal(vector<vector<int>>& triangle) {\n int n=triangle.size();\n for(int i=n-2;i>=0;i--){\n for(int j=0;j<=i;j++){\n triangle[i][j]+=min(triangle[i+1][j],triangle[i+1][j+1]);\n }\n }\n return triangl... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 0 | {
"code": "class Solution {\npublic:\n int minimumTotal(vector<vector<int>>& triangle) {\n int n = triangle.size();\n for(int i = n-2; i >=0; i--){\n for(int j = 0; j < triangle[i].size(); j++){\n triangle[i][j] += min(triangle[i+1][j], triangle[i+1][j+1]);\n }\n ... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 0 | {
"code": "class Solution {\npublic:\n int minimumTotal(vector<vector<int>>& triangle) {\n int n = triangle.size();\n int m = triangle[n - 1].size();\n\n for (int i = 1; i < n; ++i) {\n for (int j = 0; j < triangle[i].size(); ++j) {\n int x = INT_MAX;\n ... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 0 | {
"code": "class Solution {\npublic:\n int minimumTotal(vector<vector<int>>& A) {\n for(int i=1;i<A.size();i++)\n {\n for(int j=0;j<A[i].size();j++)\n {\n int p=INT_MAX;\n if(j>0)\n {\n p=min(p,A[i-1][j-1]);\n ... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 0 | {
"code": "class Solution {\npublic:\n int minimumTotal(vector<vector<int>>& triangle) {\n int n=triangle.size();\n for(int i=n-2;i>=0;i--){\n for(int j=0;j<triangle[i].size();j++){\n int minSum=min(triangle[i+1][j],triangle[i+1][j+1]);\n int currentVal=triangle[i][j];\n ... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 0 | {
"code": "#include <vector>\n#include <algorithm>\nusing namespace std;\n\nclass Solution {\npublic:\n int minimumTotal(vector<vector<int>>& triangle) {\n int n = triangle.size();\n // Start from the second last row and move upwards\n for (int i = n - 2; i >= 0; --i) {\n for (int j... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 0 | {
"code": "class Solution {\npublic:\n int minimumTotal(std::vector<std::vector<int>>& triangle) \n {\n std::vector<int> sums(triangle[triangle.size() - 1].size(), 0);\n for (int i = 0; i < triangle.size(); ++i)\n {\n for (int j = triangle[i].size()-1; j >=0 ; --j... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 0 | {
"code": "class Solution {\npublic:\n int minimumTotal(vector<vector<int>>& triangle) {\n int n = triangle.size();\n vector<int> nums = triangle[n - 1];\n for (int i = n - 2; i >= 0; i--) { \n for (int j = 0; j <= i; j++) {\n nums[j] = triangle[i][j] + min(nums[j], n... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 0 | {
"code": "class Solution {\npublic:\n int n;\n int dp[201][201];\n int solve(int i,int j,vector<vector<int>>& triangle){\n if(i==n-1)\n return triangle[n-1][j];\n\n int down=triangle[i][j]+solve(i+1,j,triangle);\n int diag=triangle[i][j]+solve(i+1,j+1,triangle);\n return... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 0 | {
"code": "class Solution {\nprivate:\n int func(vector<vector<int>>& triangle){\n int n=triangle.size();\n\n\n vector<int> dp(n);\n for (int i=0;i<n;i++) dp[i]=triangle[n-1][i];\n\n \n for (int i=n-2;i>=0;i--){\n for (int j=0;j<=i;j++){\n int first=dp[j];\n ... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 0 | {
"code": "class Solution {\npublic:\n /*\n int solve( vector<vector<int>>& triangle, int h, int p,\n vector<vector<int>>& dp){ if(h==triangle.size()) return 0;\n\n if(dp[h][p]!=-1) return dp[h][p];\n\n int a = triangle[h][p] + solve(triangle, h+1, p, dp);\n int b = tr... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 0 | {
"code": "class Solution {\npublic:\n int minimumTotal(vector<vector<int>>& triangle) {\n int row = triangle.size();\n int index = triangle[row - 1].size();\n\n vector<int>dp(index,INT_MAX);\n\n for(int i = 0;i < index;i++){\n dp[i] = triangle[row-1][i];\n }\n\n ... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 1 | {
"code": "class Solution {\npublic:\n int f(int i,int j,int m,vector<vector<int>>& triangle,vector<vector<int>>&dp){\n if(i==m-1){\n return triangle[i][j];\n }\n if(dp[i][j]!=-1) return dp[i][j];\n int down=triangle[i][j]+f(i+1,j,m,triangle,dp);\n int diag=triangle[i][... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 1 | {
"code": "class Solution {\npublic:\n int solve(vector<vector<int>>& triangle, int i, int j, vector<vector<int>> &dp){\n int n = triangle.size();\n if(i == n-1){\n return triangle[n-1][j];\n }\n\n if(dp[i][j] != -1){\n return dp[i][j];\n }\n\n int do... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 1 | {
"code": "class Solution {\npublic:\n int minimumTotal(vector<vector<int>>& triangle) {\n /*int m = triangle.size();\n if(m<1)return 0;\n int ans = 0;\n for(int i=0; i<m; i++)\n {\n int n = triangle[i].size();\n int mini = INT_MAX;\n for(int j=0;... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 1 | {
"code": "class Solution {\npublic:\n int helper(int i, int j, vector<vector<int>>& triangle,int m, vector<vector<int>>& dp)\n {\n if(i==m-1) return triangle[m-1][j];\n if(dp[i][j]!=-1) return dp[i][j];\n int down = triangle[i][j] + helper(i+1,j,triangle,m,dp);\n int diag = triangle... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 2 | {
"code": "class Solution {\npublic:\n int f(int i,int j,vector<vector<int>>& tr,vector<vector<int>>& dp)\n {\n if(i>=tr.size()||j>i||j<0)\n return INT_MAX;\n if(i==tr.size()-1)\n return tr[i][j];\n if(dp[i][j]!=-1)\n return dp[i][j];\n int d=f(i+1,j,... |
120 | <p>Given a <code>triangle</code> array, return <em>the minimum path sum from top to bottom</em>.</p>
<p>For each step, you may move to an adjacent number of the row below. More formally, if you are on index <code>i</code> on the current row, you may move to either index <code>i</code> or index <code>i + 1</code> on th... | 2 | {
"code": "class Solution {\npublic:\n \n // vector<vector<int>> dp;\n // Solution() : dp(201,vector<int>(201,-1)) {}\n // int solve(vector<vector<int>>& triangle,int i,int j){\n // if(j==triangle.size()-1) return triangle[j][i];\n // if(dp[j][i]!=-1){\n // return dp[j][i];\n ... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 0 | {
"code": "class Solution {\n // copied solution\n // https://www.hackerearth.com/practice/notes/binary-indexed-tree-or-fenwick-tree/\nprivate:\n int c[100001];\n // update the number of equal or less than x\n void update(int x) {\n while (x < 100001) {\n c[x]++;\n x += x &... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 0 | {
"code": "class Solution {\npublic:\n struct fwtree {\n int arr[100001];\n void clear() {\n memset(arr, 0, sizeof(arr));\n }\n void insert(int x) {\n if(x == 0) arr[0]++;\n while(x <= 100000) {\n arr[x]++;\n x += x & -x;\n ... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 1 | {
"code": "#define ll long long\nclass Solution {\npublic:\n ll mod = 1e9 + 7;\n vector<ll> left;\n int createSortedArray(vector<int>& instructions) {\n int n = instructions.size();\n int maxele = *max_element(instructions.begin(), instructions.end());\n left.resize(maxele + 1, 0l);\n ... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 1 | {
"code": "class Solution {\npublic:\n using ll = long long;\n \n struct FT {\n vector<ll> s;\n FT(int n) : s(n) {}\n void update(int pos, ll dif) { // a[pos] += dif\n for (; pos < ssize(s); pos |= pos + 1) s[pos] += dif;\n }\n ll query(int pos) { // sum of value... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 1 | {
"code": "class Solution {\npublic:\n const int mod=1e9+7;\n vector<int>segtree;\n void update(int node,int start,int end,int pos,int val){\n if(pos>end||pos<start)return;\n if(start==end && start==pos){\n segtree[node]+=val;\n return;\n }\n int mid=(start+e... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 1 | {
"code": "class SGT{\npublic:\n vector<int> sgt;\n int n;\n SGT(int n):n(n){\n sgt.resize(4*n, 0);\n }\n\n void build(int idx, int root, int left, int right){\n if(left == right){\n sgt[root]++;\n return;\n }\n int mid = left + ((right - left) >> 1);\n... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 1 | {
"code": "class Solution {\npublic:\n struct tree {\n int l, r, val;\n } cnt[1100011];\n void Tree(int k, int l, int r) {\n cnt[k].l = l, cnt[k].r = r;\n cnt[k].val = 0;\n if (l != r) {\n int mid = (l + r) / 2;\n Tree(2 * k, l, mid);\n Tree(2 * k ... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 1 | {
"code": "class segtree\n{\n vector<int> v;\n int n;\npublic:\n segtree(int n1)\n {\n n = n1;\n v = vector<int>(2 * n - 1, 0);\n }\n\n void update(int a, int b)\n {\n a += n - 1;\n v[a] += b;\n while(a)\n {\n a = (a - 1) / 2;\n v[a]... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 1 | {
"code": "#include <vector>\nusing namespace std;\n\nclass FenwickTree {\npublic:\n FenwickTree(int n) : tree(n + 1, 0) {}\n\n void update(int i, int delta) {\n while (i < tree.size()) {\n tree[i] += delta;\n i += i & -i;\n }\n }\n\n int query(int i) const {\n i... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 1 | {
"code": "class FenwickTree{\nprivate:\n int n;\n vector<int> arr;\n vector<int> farr;\n\npublic:\n FenwickTree(){\n n = 100001;\n farr.resize(100001, 0);\n }\n\n FenwickTree(vector<int>& ar){\n n = 100001;\n // arr.resize(n);\n farr.resize(100001, 0);\n\n ... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 1 | {
"code": "class Solution {\n int m = 1e5+2;\n vector<long long>fw;\n int mod = 1e9 + 7;\npublic:\n void update(int num, int cnt){\n while(num < m){\n fw[num] += cnt;\n num += (num & (-num));\n }\n }\n int sum(int i){\n int ans = 0;\n for(int j=i;j>0... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 1 | {
"code": "class Solution {\npublic:\n int MOD = 1000000007; \n int createSortedArray(vector<int>& instructions) {\n int m = 100001; \n vector<int> tree(m * 2, 0); \n\n long cost = 0;\n for (int x : instructions) {\n cost += min(query(0, x, tree, m), query(x + 1, m, tre... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 1 | {
"code": "class Solution {\npublic:\n int createSortedArray(vector<int>& instructions) {\n int m = (int)1e5 + 1;\n vector<int> tree(m * 2);\n\n long cost = 0;\n long MOD = (int)1e9 + 7;\n for (int x : instructions) {\n cost += min(query(0, x, tree, m), query(x + 1, m,... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "class Solution {\npublic:\n int mod = 1000000007;\n int createSortedArray(vector<int>& instructions) {\n int n = 100002;\n vector<int> bitree(n);\n unordered_map<int, int> mp;\n int ans = 0;\n for( int i=0 ; i<instructions.size() ; i++ ){\n int num = inst... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "#include <vector>\n#include <unordered_map>\n#include <algorithm>\n\nusing std::vector;\nusing std::unordered_map;\n\nnamespace cust\t\t\t//customized / non-standard\n{\n\tclass segment_tree\n\t{\n\t\tpublic:\n\t\t\tsegment_tree(int n) : n { n }\n\t\t\t{\n\t\t\t\timpl.assign(2 * n - 1, 0);\n\t\t\t}\n\n\t\t... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "class Solution {\npublic:\n class BIT {\n public:\n BIT(int size): n(size), bit(n+1, 0) {}\n\n void add(int x) {\n for (int i=x; i<=n; i+=lowbit(i)) {\n bit[i]++;\n }\n }\n\n int count(int x) {\n int sum = 0;\n for... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "class Solution {\npublic:\n class BIT {\n public:\n BIT(int size): n(size), bit(n+1, 0) {}\n\n void add(int x) {\n for (int i=x; i<=n; i+=lowbit(i)) {\n bit[i]++;\n }\n }\n\n int count(int x) {\n int sum = 0;\n for... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "class Solution {\npublic:\n void update(int i, int val, vector<int>& bit){\n int ind=i;\n while (ind<bit.size()){\n bit[ind]+=val;\n ind+=(ind&(-ind));\n }\n }\n int sum(int i, vector<int>& bit){\n int ans=0;\n for (int j=i; j>0; j-=(j&(-j))... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "class Node{\n public:\n int start,end,value;\n Node*left,*right;\n Node(int start,int end){\n this->start = start;\n this->end = end;\n this->value = 0;\n this->left = NULL;\n this->right = NULL;\n }\n};\nNode* build(int start,int end){\n Node*node = new... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "struct Node {\n Node* lft = NULL;\n Node* rht = NULL;\n int V = 0;\n int S = 0;\n int C = 0;\n Node(int V) {\n this -> V = V;\n }\n};\nconst int mod = 1e9 + 7;\nclass Solution {\npublic:\n int createSortedArray(vector<int>& A) {\n auto build = [&] (auto &&build, int L, int R, vector <int>... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "class Node{\n public:\n Node* left ;\n Node* right ;\n int s ;\n int e ;\n int cnt ;\n\n Node(int ss , int ee){\n s = ss ;\n e = ee ;\n cnt = 0 ;\n left = NULL ;\n right = NULL ;\n }\n};\n\nclass Segment{\n public:\n Node* root ;\n\n Segme... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "class SegmentTree {\n vector<int> tree;\n int maxVal;\n\npublic:\n SegmentTree(int maxVal) : maxVal(maxVal) {\n tree.resize(4 * maxVal, 0);\n }\n\n void update(int node, int start, int end, int idx, int value) {\n if (start == end) {\n // Leaf node: update the freque... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "\nclass segmentTree {\n\nprivate:\n\n vector<int> segTree;\n int n;\n\n int mod = 1e9 + 7;\n\npublic:\n\n segmentTree() {\n n = 100007;\n segTree.resize(4*n, 0);\n }\n\n void updateVal(int uIdx, int i, int j, int segIdx) {\n\n if (i == j && i == uIdx) {\n s... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "class BIT{\n public:\n int N; \n vector<long long>bitArr; // Note: all arrays are 1-index\n vector<long long>nums;\n long long M = 1e9+7;\n\n void init(int N)\n {\n this->N = N;\n bitArr.resize(N+1);\n nums.resize(N+1); \n }\n\n // increase nums[i] ... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "class BIT{\n public:\n int N; \n vector<long long>bitArr; // Note: all arrays are 1-index\n vector<long long>nums;\n long long M = 1e9+7;\n\n void init(int N)\n {\n this->N = N;\n bitArr.resize(N+1);\n nums.resize(N+1); \n }\n\n // increase nums[i] ... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "class bst {\npublic:\n vector<vector<int>> nodes;\n int total;\n void construct(int index, int first, int last) {\n if (first == last) return;\n int mid = (first+last)/2;\n nodes[index][0] = mid;\n construct(2*index+1, first, mid);\n construct(2*index+2, mid+1, l... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "#define ll long long int\nclass SegmentTree{\n ll n ;\n vector < ll > nodes ;\n\n void update ( ll index , ll val , ll low , ll high , ll node){\n if ( low == high ){\n nodes [node] += val;\n return ;\n }\n ll mid = low + ( high - low ) / 2;\n if (... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "class Solution {\npublic:\n unordered_map<int, int> m;\n vector<int> tree;\n const int maxn = 1e5+3;\n void update(int id, int l, int r, int ql, int qr, int val) {\n if (qr < l || r < ql) return;\n if (ql <= l && r <= qr) {\n tree[id]++;\n return;\n }\... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "class Solution {\npublic:\n long long cost[100005], sorted[100005], mod=1e9+7, count[100005];\n int createSortedArray(vector<int>& nums) {\n int n = nums.size();\n for(int i=0;i<n;i++){\n sorted[i] = nums[i];\n }\n\n helper(nums, 0, n-1);\n long long res=... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "class Solution {\npublic:\n long long cost[100005], sorted[100005], mod=1e9+7, count[100005];\n int createSortedArray(vector<int>& nums) {\n int n = nums.size();\n for(int i=0;i<n;i++){\n sorted[i] = nums[i];\n }\n\n helper(nums, 0, n-1);\n long long res=... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\n#include <bits/stdc++.h>\n\nusing namespace __gnu_pbds;\nusing namespace std;\n\ntypedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;\nclass Solution {\npublic:\n int freq... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "#include<ext/pb_ds/assoc_container.hpp>\n#include<ext/pb_ds/tree_policy.hpp>\nusing namespace __gnu_pbds;\ntypedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; \n// find_by_order, order_of_key\n\n#define mod 1000000007\nclass Solution {\npublic:\n int stric... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "#include<ext/pb_ds/assoc_container.hpp>\n#include<ext/pb_ds/tree_policy.hpp>\nusing namespace __gnu_pbds;\ntypedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; \n// find_by_order, order_of_key\n\n#define mod 1000000007\nclass Solution {\npublic:\n int stric... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "/* Segment Tree \nUse of each segment tree leaf node to represent a number in instructions, the info of these leaf nodes are the count of their appearence so far when iterating through the instructions array.\n\n### Implementation Walkthrough\n1. **Initialization and Preprocessing:**\n - Convert the `ins... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "class Solution {\n class SegTreeNode\n {\n public:\n SegTreeNode* left;\n SegTreeNode* right;\n int start, end;\n int info; \n SegTreeNode(int a, int b):start(a),end(b),info(0),left(NULL),right(NULL){}\n };\n \n void init(SegTreeNode* node, in... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "typedef long long LL;\nclass Solution {\n class SegTreeNode {\n public:\n SegTreeNode* left;\n SegTreeNode* right;\n int start, end;\n int info;\n SegTreeNode(int a, int b) : start(a), end(b), info(0), left(NULL), right(NULL) {}\n };\n void init(SegTreeNod... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "class Solution {\npublic:\n vector<int>seg;\n vector<int>v;\n int mod=1e9+7;\n int build(int node,int l,int r){\n if(l>r)\n return 0;\n if(l==r){\n return seg[node]=v[l];\n }\n int mid=(l+r)/2;\n return seg[node]=build(2*node+1,l,mid)+build(... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "class Solution {\nprivate:\n vector<int> csel, cgel;\n int mod = 1e9+7;\n \n void merge(vector<int> &a, vector<int> &inx1, vector<int> &inx2, int left, int mid, int right) {\n vector<int> tmp(right-left+1);\n \n int i = left, j = mid+1, k = 0;\n while(i <= mid && j ... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "void update(vector<long long> &seg_tree, int ls, int rs, int l, int r, long long pos, int addV){\n\n if(ls<=l && r<=rs){\n if(l!=r){\n long long mid = ((long long)l+(long long)r)/2;\n\n update(seg_tree, ls, rs, l, mid, 2*pos+1, addV);\n update(seg_tree, ls, rs, mi... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 2 | {
"code": "class Solution {\n vector<int> seg;\n int M =1e9+7;\npublic:\n int createSortedArray(vector<int>& instructions) {\n int n = *max_element(instructions.begin(),instructions.end());\n vector<int> freq(n+1,0);\n seg.resize(4*1e6);\n build(freq,0,0,n);\n int ans =0;\n... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 3 | {
"code": "#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\n#include <bits/stdc++.h>\n\nusing namespace __gnu_pbds;\nusing namespace std;\n\n \n#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> \nclass Solution {\npublic:\n long... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 3 | {
"code": "#include<ext/pb_ds/assoc_container.hpp>\n#include<ext/pb_ds/tree_policy.hpp>\nusing namespace __gnu_pbds;\n\ntypedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;\n\nclass Solution {\n int mod = 1e9 + 7;\npublic:\n int createSortedArray(v... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 3 | {
"code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\n\nusing namespace std;\nusing namespace __gnu_pbds;\n\n\ntypedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> mset;\n\n\nclass Solution {\npublic:\n int createSorte... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 3 | {
"code": "#include<ext/pb_ds/assoc_container.hpp>\n#include<ext/pb_ds/tree_policy.hpp>\nusing namespace __gnu_pbds;\ntypedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> oset;\n\nclass Solution {\npublic:\n int createSortedArray(vector<int>& instructions) {\n int n ... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 3 | {
"code": "#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\nusing namespace __gnu_pbds;\n\nclass Solution {\npublic:\n const int mod = 1e9 + 7;\n template <typename T, typename CMP = less<T>>\n using ordered_set = tree<T, null_type, CMP, rb_tree_tag, tree_order_statistics_node_... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 3 | {
"code": "class Solution {\npublic:\n int MOD = 1e9 + 7;\n int createSortedArray(vector<int>& instructions) {\n int n = instructions.size();\n\n\n vector<long> cntlarger(n, 0);\n vector<int> sorted(n); // index in sorted order\n for (int i = 0; i < n; i++)\n sorted[i] = i... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 3 | {
"code": "class SegTreeNode\n{\npublic:\n SegTreeNode* left;\n SegTreeNode* right;\n int start;\n int end;\n int info;\n SegTreeNode(int a, int b)\n {\n left = nullptr;\n right = nullptr;\n start = a;\n end = b;\n info = 0;\n }\n};\nclass Solution {\npublic:... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 3 | {
"code": "#include <ext/pb_ds/assoc_container.hpp> \n#include <ext/pb_ds/tree_policy.hpp> \nusing namespace __gnu_pbds; \n \n#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> \n \n\n\nclass Solution {\npublic:\n int mod=1e9+7;\n int createSo... |
1,772 | <p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <stron... | 3 | {
"code": "#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\n#include <bits/stdc++.h>\n#define ll long long \nusing namespace __gnu_pbds;\nusing namespace std;\nll mod = 1e9+7;\ntypedef tree<pair<ll,ll> , null_type, less_equal<pair<ll,ll> >, rb_tree_tag,tree_order_statistics_node_update>... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.