id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 1 | {
"code": "class Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n bool even = true;\n int n = mat[0].size();\n k = k % n;\n if (k == 0) return true;\n for (int i=0; i<mat.size(); i++, even = !even) {\n vector<int> shift (mat[i].size());\n ... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 2 | {
"code": "#include <vector>\n#include <algorithm> // For std::rotate_copy\n\nusing namespace std;\n\nclass Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n int n = mat[0].size();\n k %= n;\n for (const auto& m : mat) {\n vector<int> shifted_m(n);\n ... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 2 | {
"code": "#include <vector>\n#include <iostream>\n\nclass Solution {\npublic:\n bool areSimilar(std::vector<std::vector<int>>& mat, int k) {\n int cols = mat[0].size(); // Number of columns in the matrix\n k %= cols; // Adjust k to be within the bounds of the row length\n\n for (const auto& r... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 2 | {
"code": "class Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n bool even = true;\n k = k % mat[0].size();\n for (int i=0; i<mat.size(); i++, even = !even) {\n vector<int> shift (mat[i].size());\n if (even) {\n for (int j=0; j<ma... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 2 | {
"code": "class Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n int element;\n for (int i=0;i<mat.size();i++){\n vector<int> row = mat[i];\n for (int y=0;y<k%row.size();y++){\n if (i%2){\n element = row.back();\n ... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 2 | {
"code": "class Solution {\npublic:\n bool isEqual(vector<vector<int>>& temp,vector<vector<int>>&mat){\n for(int i=0;i<mat.size();i++){\n for(int j=0;j<mat[0].size();j++){\n if(mat[i][j]!=temp[i][j]) return false;\n }\n }\n return true;\n }\n void sh... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 2 | {
"code": "class Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n int rows = mat.size();\n int cols = mat[0].size();\n if (k % cols == 0) return true;\n for (int i = 0; i < rows; i++) {\n vector<int> modified;\n if (i & 1) {\n ... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 2 | {
"code": "class Solution {\npublic:\n void shiftleft(vector<vector<int>>& mat , int i){\n int num = mat[i][0];\n int j = 1 ;\n for(; j < mat[0].size() ; j++){\n mat[i][j-1] = mat[i][j];\n }\n mat[i][j-1] = num;\n }\n void shiftright(vector<vector<int>>& mat , in... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 2 | {
"code": "class Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n int n = mat.size(); // Number of rows\n int m = mat[0].size(); // Number of columns\n int x = k % m; // Shift amount based on columns\n vector<vector<int>> ans = m... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n vector<vector<int>> copyMat = mat;\n for(int i = 0; i < mat.size(); i++){\n for(int x = 0; x < k; x++){\n mat[i].push_back(mat[i][0]);\n mat[i].erase(mat[i].begin());\n... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n int m=mat.size();\n int n=mat[0].size();\n vector<vector<int>> A(m,vector<int>(n));\n for(int i=0;i<m;++i){\n for(int j=0;j<n;++j)A[i][j]=mat[i][j];\n }\n for(int a=0;a<k... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n vector<vector<int>> comp(mat.size(), vector<int>(mat[0].size()));\n for (int i = 0; i < mat.size(); i++)\n for (int j = 0; j < mat[i].size(); j++)\n comp[i][j] = mat[i][j];\n f... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n int m = mat.size(), n = mat[0].size();\n for(int i = 0 ; i < m ; i++){\n vector<int> vec;\n if(i & 1){\n int x = (n - (k % n)) % n;\n for(int j = x ; j < n ;... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n int row = mat.size();\n int col = mat.at(0).size();\n vector<vector<int>> original = mat;\n\n if (k > col) {\n k = k % col;\n }\n\n while (k > 0) {\n for (int ... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n void lr(vector<int>& v, int k) {\n int n = v.size();\n k %= n;\n vector<int> temp(n);\n for (int i = 0; i < n; i++) {\n temp[i] = v[(i + k) % n];\n }\n v = temp;\n }\n\n void rr(vector<int>& v, int k) {\n int n... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n void rs(vector<int>& vec, int k) {\n int size = vec.size();\n k = k % size;\n reverse(vec.begin(), vec.end());\n reverse(vec.begin(), vec.begin() + k);\n reverse(vec.begin() + k, vec.end());\n }\n void ls(vector<int>& vec, int k) {\n ... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n void rs(vector<int>& vec, int k) {\n int size = vec.size();\n k = k % size;\n reverse(vec.begin(), vec.end());\n reverse(vec.begin(), vec.begin() + k);\n reverse(vec.begin() + k, vec.end());\n }\n void ls(vector<int>& vec, int k) {\n ... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n void left(vector<int>&nums,int k){\n int n=nums.size();\n k=k%n;\n reverse(nums.begin(),nums.end());\n reverse(nums.begin(),nums.begin()+n-k);\n reverse(nums.begin()+n-k,nums.end());\n }\n void right(vector<int>&nums,int k){\n k... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n int m = mat.size();\n int n = mat[0].size();\n vector<vector<int>> matrix(m, vector<int>(n, 0));\n for (int i = 0; i < m; i++) {\n vector<int> arr(n);\n arr = mat[i];\n ... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n vector<vector<int>>curr = mat , pre = mat ; \n int n = mat.size() , m = mat[0].size() ; \n while(k--){\n for(int i = 0 ; i < n ; i++){\n if(i%2 == 1){\n ... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n bool isSame(vector<vector<int>> a, vector<vector<int>> b){\n int m=a.size(), n=a[0].size();\n for (int i=0;i<m;i++){\n for (int j=0;j<n;j++){\n if (a[i][j]!=b[i][j]) return false;\n }\n }\n return true;\n }\n... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n vector<vector<int>> g=mat;\n vector<vector<int>> ans(mat.size(),vector<int>(mat[0].size(),0));\n int n=mat.size(),m=mat[0].size();\n\n while(k--){\n for(int i=0;i<n;i++){\n ... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n void rot(vector<int>& arr, int k, bool leftShift) {\n int n = arr.size();\n k = k % n;\n if (k == 0)\n return;\n\n if (leftShift) {\n vector<int> temp(arr.begin() + k, arr.end());\n temp.insert(temp.end(), arr.begin... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n int n=mat.size();\n int m=mat[0].size();\n k=k%m;\n vector<vector<int>> ans(n,vector<int>(m));\n\n for(int i=0;i<n;i++)\n {\n vector<int> temp(2*m);\n for(int ... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n vector<int> left(vector<int> &arr, int k){\n for(int i = 0; i < k; i++){\n int temp = arr[0];\n arr.erase(arr.begin());\n arr.push_back(temp);\n }\n return arr;\n }\n vector<int> right(vector<int> &arr, int k){\n ... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n vector<vector<int>> v = mat ;\n int mod = 0 ;\n int n = mat[0].size() ;\n k = k % n;\n for(int i=0 ; i<v.size() ; i++) {\n if (i % 2 == 0) {\n rotate(v[i].begin(),... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n vector<vector<int>> v = mat ;\n int mod = 0 ;\n int n = mat[0].size() ;\n k = k % n;\n for(int i=0 ; i<v.size() ; i++) {\n if (i % 2 == 0) {\n rotate(v[i].begin(),... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n void cyclicShiftLeft(vector<int>& row, int k) {\n int n = row.size();\n k = k % n;\n rotate(row.begin(), row.begin() + k, row.end());\n }\n void cyclicShiftRight(vector<int>& row, int k) {\n int n = row.size();\n k = k % n;\n ro... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n\n void reverse(int start, int end, vector<int> &vec){\n while(start<=end) {\n int temp = vec[start];\n vec[start] = vec[end];\n vec[end] = temp;\n start++;\n end--;\n }\n }\n bool areSimilar(vector<vec... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n void shiftLeft(vector<int>& nums, int k){\n // left shift for even indices\n vector<int> temp;\n for(int i = k; i < nums.size(); i++){\n temp.push_back(nums[i]);\n }\n\n for(int i = 0; i< k; i++){\n temp.push_back(nums[... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n void leftShift(vector<int>& arr, int k) {\n int n = arr.size();\n k = k % n; // Ensure k is within the bounds of the array size\n std::rotate(arr.begin(), arr.begin() + k, arr.end());\n }\n\n void rightShift(vector<int>& arr, int k) {\n int n = arr... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n bool areSimilar(vector<vector<int>>& mat, int k) {\n int m = mat.size();\n int n = mat[0].size();\n vector<vector<int>> cp = mat;\n int kn = k % n;\n for (int i = 0; i < m; i++) {\n if (i % 2 == 0) {\n std::rotate(m... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n\nvoid reverse(vector<int>&curr,int i,int j)\n{\n while(i<j)\n {\n swap(curr[i],curr[j]);\n i++;\n j--;\n }\n}\n bool areSimilar(vector<vector<int>>& mat, int k) {\n \n\n int row=mat.size();\n int col=mat[0].size();\n k... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n vector <int> shiftLeft (vector <int> row) {\n vector <int> output (row.begin () + 1, row.end ());\n output.push_back (row [0]);\n return output;\n }\n\n vector <int> shiftRight (vector <int> row) {\n vector <int> output = {row [row.size () - ... |
3,215 | <p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. The matrix rows are 0-indexed.</p>
<p>The following proccess happens <code>k</code> times:</p>
<ul>
<li><strong>Even-indexed</strong> rows (0, 2, 4, ...) are cyclically shifted to the left.</li>
</ul>
<p><img src="... | 3 | {
"code": "class Solution {\npublic:\n void helper(vector<vector<int>>&res){\n for(int i=0;i<res.size();i++){\n vector<int>temp=res[i];\n if(i%2==0){\n int te=temp[0];\n for(int j=1;j<temp.size();j++){\n temp[j-1]=temp[j];\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 0 | {
"code": "class Solution {\npublic:\n bool isVowel(char ch){\n return ((ch=='a')||(ch=='e')||(ch=='i')||(ch=='o')||(ch=='u'));\n }\n int beautifulSubstrings(string s, int k) {\n int constant=0,vowel=0,res=0;\n for(int i=0;i<s.length();i++){\n constant=0;\n vowel=0;... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 0 | {
"code": "class Solution {\npublic:\n bool isVowel(char ch)\n {\n if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') return true;\n return false;\n }\n int beautifulSubstrings(string s, int k) {\n int result = 0;\n int vowels = 0, consonants = 0;\n for(in... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 0 | {
"code": "class Solution {\npublic:\n bool isVowel (char ch) {\n return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');\n }\n int beautifulSubstrings(string s, int k) {\n int cnt = 0;\n int n = s.size();\n for (int i=0; i<n; i++) {\n int vowelCnt = 0, ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 0 | {
"code": "class Solution {\npublic:\n int isVowel(char c) {\n if (c == 'a' || c == 'e' || c== 'i' || c == 'o' || c == 'u') return 1;\n return -1;\n }\n\n int beautifulSubstrings(string s, int k) {\n int n = s.length();\n int count = 0;\n for (int i = 0; i < n; i++) {\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 0 | {
"code": "class Solution {\npublic:\n\n bool isVowel(char &ch){\n return ch == 'a' || ch == 'e' ||ch == 'i' || ch == 'o' ||ch == 'u';\n }\n\n int beautifulSubstrings(string s, int k) {\n int n = s.length();\n int result = 0;\n for(int i=0 ; i<n ; i++){\n int vowels = 0... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 1 | {
"code": " class Solution {\n \n bool check( int k, int &vowels, int &consonants) {\n \n if (vowels == consonants && (vowels * consonants) % k == 0) {\n return true;\n }\n return false;\n }\n\npublic:\n int beautifulSubstrings(string s, int k) {\n int n = s.length... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 1 | {
"code": "class Solution {\npublic:\n\n bool isVowel(char &ch){\n return ch == 'a' || ch == 'e' ||ch == 'i' || ch == 'o' ||ch == 'u';\n }\n\n int beautifulSubstrings(string s, int k) {\n int n = s.length();\n int result = 0;\n for(int i=0 ; i<n ; i++){\n int vowels = 0... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 2 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n const auto isVowel = [](const char c) -> bool {\n static std::unordered_set<char> vowels = {'a', 'e', 'i', 'o', 'u'};\n return vowels.contains(c);\n };\n\n int count = 0;\n for (int... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 2 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n int n = s.size();\n string vow = \"aeiou\";\n int res = 0;\n for(int i = 0; i < n; i++){\n int vowels = 0, consonants = 0;\n for(int j = i; j < n; j++){\n if(vow.find... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 2 | {
"code": "class Solution {\nprivate:\n bool check(vector<int>& prefixSum, int start, int end, int k) {\n int vowelCount = prefixSum[end + 1] - prefixSum[start];\n int consonantCount = (end - start + 1) - vowelCount;\n\n return (vowelCount == consonantCount) && ((vowelCount * consonantCount) %... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 2 | {
"code": "class Solution {\nprivate:\n bool check(vector<int>& prefixSum, int start, int end, int k) {\n int vowelCount = prefixSum[end] - (start != 0 ? prefixSum[start - 1] : 0);\n int consonantCount = (end - start + 1) - vowelCount;\n\n return (vowelCount == consonantCount) && ((vowelCount ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 2 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n set<char> vowels = {'a', 'e', 'i', 'o', 'u'};\n int n = s.length();\n int count = 0;\n for (int i = 0; i < n; i++) {\n int v = 0, c = 0;\n for (int j = i; j < n; ++j) {\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 2 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n int n = s.size();\n int count = 0;\n vector<int> vowelPrefix(n + 1, 0);\n vector<int> consonantPrefix(n + 1, 0);\n for (int i = 0; i < n; i++) {\n vowelPrefix[i + 1] =\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "#include <vector>\n#include <string>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n vector<int> cnt_0(s.size() + 1, 0);\n vector<int> cnt_1(s.size() + 1, 0);\n\n // Compute prefix sums for vowels and consonants\n for (size_... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n int n = s.size();\n int ans = 0;\n \n // Iterate over all possible starting points for substrings\n for (int i = 0; i < n; i++) {\n string vowels = \"aeiou\";\n int vowel = 0... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n int n = s.size();\n vector<int> nv(n);\n unordered_set<char> st = {'a','e','i','o','u'};\n for(int i=0;i<n;i++){\n if(st.find(s[i])!=st.end())\n nv[i] = 1 + (i==0?0:nv[i-1]);\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n ios_base::sync_with_stdio(false); cin.tie(0);\n set<char> vowels = {'u', 'e', 'o', 'a', 'i'};\n vector<int> psv(s.length()), psc(s.length());\n for (int i=0;i<s.length();++i){\n if (i==0){\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n ios_base::sync_with_stdio(false); cin.tie(0);\n set<char> vowels = {'u', 'e', 'o', 'a', 'i'};\n vector<int> psv(s.length()), psc(s.length());\n for (int i=0;i<s.length();++i){\n if (i==0){\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n ios_base::sync_with_stdio(false); cin.tie(0);\n set<char> vowels = {'u', 'e', 'o', 'a', 'i'};\n vector<int> psv(s.length()), psc(s.length());\n for (int i=0;i<s.length();++i){\n if (i==0){\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n ios_base::sync_with_stdio(false); cin.tie(0);\n set<char> vowels = {'u', 'e', 'o', 'a', 'i'};\n vector<int> psv(s.length()), psc(s.length());\n for (int i=0;i<s.length();++i){\n if (i==0){\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n int n=s.size();\n\n int ans=0;\n unordered_set<int>st={'a','e','i','o','u'};\n for(int i=0;i<n;i++){\n int v=0,c=0;\n string temp=\"\";\n for(int j=i;j<n;j++){\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\n bool isvowel(char c){\n return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';\n }\npublic:\n int beautifulSubstrings(string s, int k) {\n vector<pair<int, int>> v;\n int p1 = 0, p2 = 0, ans = 0;\n v.push_back({0, 0});\n for(int i = 0... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n int n=s.size();\n vector<int> vow;\n vector<int> conso;\n int v=0,c=0;\n for(int i=0;i<n;i++){\n if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'){\n v++;\n }else{\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n int n=s.size();\n vector<int> vow;\n vector<int> conso;\n int v=0,c=0;\n for(int i=0;i<n;i++){\n if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'){\n v++;\n }else{\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n int n = s.length();\n vector<int> vowels;\n int count = 0;\n string t = \"aeiou\";\n for(int i = 0;i < n;i++){\n string ch = \"\";\n ch += s[i];\n count += t.find(... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n\n\n int beautifulSubstrings(string s, int k) {\n int ans=0;\n map<char,bool> m;\n m['a']=true;\n m['e']=true;\n m['i']=true;\n m['o']=true;\n m['u']=true;\n for(int i=0;i<s.size();i++)\n {\n int v=0,c=0... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution\n{\npublic:\n int beautifulSubstrings(string s, int k)\n {\n int n = s.length();\n unordered_map<char, bool> mp;\n char vowels[] = {'a', 'e', 'i', 'o', 'u'};\n for (char c : vowels)\n {\n mp[c] = true;\n }\n for (char c = 'a';... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "// s is beautiful if\n// 1. vowels == consonants\n// 2. (vowels * consonants) % k == 0\n\n// Return: # of non-empty beautiful substrings\n\n// Constraints:\n// 1 <= s.length <= 1000\n// 1 <= k <= 1000\n// s consists of only English lowercase letters.\n\nclass Solution\n{\npublic:\n int beautifulS... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "// s is beautiful if\n// 1. vowels == consonants\n// 2. (vowels * consonants) % k == 0\n\n// Return: # of non-empty beautiful substrings\n\n// Constraints:\n// 1 <= s.length <= 1000\n// 1 <= k <= 1000\n// s consists of only English lowercase letters.\n\nclass Solution\n{\npublic:\n int beautifulS... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "// s is beautiful if\n// 1. vowels == consonants\n// 2. (vowels * consonants) % k == 0\n\n// Return: # of non-empty beautiful substrings\n\n// Constraints:\n// 1 <= s.length <= 1000\n// 1 <= k <= 1000\n// s consists of only English lowercase letters.\n\nclass Solution\n{\npublic:\n int beautifulS... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "// s is beautiful if\n// 1. vowels == consonants\n// 2. (vowels * consonants) % k == 0\n\n// Return: # of non-empty beautiful substrings\n\n// Constraints:\n// 1 <= s.length <= 1000\n// 1 <= k <= 1000\n// s consists of only English lowercase letters.\n\nclass Solution\n{\npublic:\n int beautifulS... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n int n=s.size();\n vector<int> vowel(n+1), cons(n+1);\n unordered_map<char, bool> mp;\n mp['a']=1 , mp['e']=1, mp['i']=1, mp['o']=1, mp['u'] = 1;\n for(int i=0;i<n;i++){\n if(mp[s[i]]){\... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n int n=s.size(),ans=0;\n vector<int>v(n),c(n);\n map<char,int> mp;\n mp['a']=1;mp['e']=1;mp['i']=1;mp['o']=1;mp['u']=1;\n for (int i=0;i<n;i++){\n v[i]=mp[s[i]];\n c[i]=1-v[... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\nbool isvowel(char ch){\n return (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u');\n}\n int beautifulSubstrings(string s, int k) {\n unordered_map<int,vector<int>>mpp;\n mpp[0].push_back(-1);\n int n=s.size();\n int ans=0;\n \... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n int c = 0;\n int v = 0;\n int n = s.size();\n int ans = 0;\n unordered_map<int, vector<int>> mp;\n for(int i = 0; i < n; i++)\n {\n if( s[i] == 'a' || s[i] == 'e' || s[i] ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int solve(string s, int k) {\n if (k+k > s.size()) return 0;\n int v = 0, c = 0;\n int ans = 0;\n\n string vow = \"aeiou\";\n for (int i = 0; i < k+k; i++) {\n if (vow.find(s[i]) != string::npos) {\n v++;\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\n bool isVowel(char c){\n if(c == 'a' \n || c == 'e'\n || c == 'i'\n || c == 'o'\n || c == 'u'){\n return true;\n }\n else \n return false;\n }\npublic:\n int beautifulSubstrings(string ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n int vows = 0, consonants = 0;\n int n = s.length();\n int ans = 0;\n vector<int> vv(n, 0);\n vector<int> vc(n, 0);\n unordered_map<int, vector<int>> difMp;\n for (int i = 0; i ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n int n=s.length();\n int ans=0;\n vector<vector<int>>pre(n,vector<int>(2,0));\n if(s[0]=='a' || s[0]=='e' || s[0]=='i' || s[0]=='o' || s[0]=='u') pre[0][0]++;\n else\n pre[0][1]... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n int l = s.length();\n vector<vector<int>> letters(l, vector<int>(2, 0));\n\n if (s[0] == 'a' || s[0] == 'e' || s[0] == 'i' || s[0] == 'o' || s[0] == 'u') {\n letters[0][0] = 1;\n } else {\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n\n int n = s.length();\n unordered_map<int, vector<int>> mp; //val , idx arr\n unordered_set<char> us;\n us.insert('a');\n us.insert('e');\n us.insert('i');\n us.insert('o');\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "typedef long long int llt;\nclass Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n llt answer = 0;\n unordered_map<llt,vector<llt>> mp;\n mp[0].push_back(-1);\n llt v = 0 , c = 0;\n unordered_set<char> st;\n st.insert('a') , st.insert('e'... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n\n int n = s.length();\n unordered_map<int, vector<int>> mp; //val , idx arr\n unordered_set<char> us;\n us.insert('a');\n us.insert('e');\n us.insert('i');\n us.insert('o');\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\n public:\n int beautifulSubstrings(string s, int k) {\n const int root = getRoot(k);\n int ans = 0;\n int vowels = 0;\n int vowelsMinusConsonants = 0;\n // {(vowels, vowelsMinusConsonants): count}\n unordered_map<pair<int, int>, int, PairHash> prefixCount{{{0, 0}, 1}};\... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n constexpr std::string_view VOWELS = \"aeiouAEIOU\";\n auto calcRoot = [](int v) -> int\n {\n for (int i = 1; i <= v; ++i)\n if (i * i % v == 0)\n return i;\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n int n = s.size(), vow=0, cons=0, ans=0;\n unordered_set<char> vowels({'a','e','i','o','u'});\n vector<vector<int>> count(n, vector<int>(2, 0));\n for(int i=0; i<n; i++){\n if(vowels.find(s[i])... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n int n = s.size();\n vector<vector<int>> cnt(n+5,vector<int>(3));\n vector<char> vo = {'a','e','i','o','u'};\n set<char> st(vo.begin(),vo.end());\n for (int g=0; g<n; g++){\n for (int ch... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n long long ans = 0;\n map<pair<int,int>,int> mp;\n int n = s.size();\n int p = 1;\n // int i = 1;\n while(p<n){\n if(p*p%k == 0){\n break;\n }\n p++;\n }\... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n using ll = long long;\n\n bool isvowel(char c) {\n return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');\n }\n\n long long beautifulSubstrings(string s, int k) {\n vector<ll> delta(s.size() + 1, 0);\n for(ll i = 1; i <= s.size(); i++... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "// Time: O(n + sqrt(k))\n// Space: O(n)\n\n// number theory, prefix sum, freq table\nclass Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n static const unordered_set<char> VOWELS = {'a', 'e', 'i', 'o', 'u'};\n \n vector<int> prefix(size(s) + 1);\n for (int i =... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n\n bool isVowel(char ch) {\n return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';\n }\n typedef long long ll;\n int beautifulSubstrings(string s, int k) {\n ll vowel = 0;\n ll ans = 0;\n ll cons = 0;\n unordered... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n int tar = 1;\n while((tar * tar) % k != 0) tar++;\n map<int, map<int, int>> cnt;\n int cntv = 0, cntc = 0, ans = 0;\n cnt[0][0] = 1;\n for(int i=0;i<s.size();i++){\n if(string(\"... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n int beautifulSubstrings(string s, int k) {\n unordered_map<int, vector<int>> grps;\n grps[0].push_back(0);\n\n string vowels(\"aeiou\");\n for (int i = 0, presum = 0; i < s.size(); i++) {\n vowels.find(s[i]) != string::npos ? ++presum : ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n #define ll long long\n bool isVowel(char ch){\n return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';\n }\n int beautifulSubstrings(string s, int k) {\n // generate all substrings:-\n ll vowel = 0;\n ll consonants = 0;\n ... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "#define ll long long int\n\nclass Solution {\npublic:\n long long beautifulSubstrings(string s, int k) {\n vector<int>v;\n int n=s.length();\n v.push_back(1);\n for(int i=2;i<=n;i+=2){\n int j=i/2;\n if((j*j)%k==0) v.push_back(i);\n }\n uno... |
3,210 | <p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * c... | 3 | {
"code": "class Solution {\npublic:\n #define ll long long\n bool isVowel(char ch){\n return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';\n }\n int beautifulSubstrings(string s, int k) {\n // generate all substrings:-\n ll vowel = 0;\n ll consonants = 0;\n ... |
3,219 | <p>You are given a <strong>0-indexed</strong> array of <strong>positive</strong> integers <code>nums</code> and a <strong>positive</strong> integer <code>limit</code>.</p>
<p>In one operation, you can choose any two indices <code>i</code> and <code>j</code> and swap <code>nums[i]</code> and <code>nums[j]</code> <stron... | 0 | {
"code": "class Solution {\npublic:\n vector<int> lexicographicallySmallestArray(vector<int>& nums, int limit) {\n vector<int> indexes(nums.size());\n iota(indexes.begin(), indexes.end(), 0);\n sort(indexes.begin(), indexes.end(), [&](auto a, auto b) {\n return nums[a] < nums[b];\n... |
3,219 | <p>You are given a <strong>0-indexed</strong> array of <strong>positive</strong> integers <code>nums</code> and a <strong>positive</strong> integer <code>limit</code>.</p>
<p>In one operation, you can choose any two indices <code>i</code> and <code>j</code> and swap <code>nums[i]</code> and <code>nums[j]</code> <stron... | 0 | {
"code": "class Solution {\npublic:\n vector<int> lexicographicallySmallestArray(vector<int>& nums, int limit) {\n vector<int> indexes(nums.size());\n iota(indexes.begin(), indexes.end(), 0);\n sort(indexes.begin(), indexes.end(), [&](auto a, auto b) {\n return nums[a] < nums[b];\n... |
3,219 | <p>You are given a <strong>0-indexed</strong> array of <strong>positive</strong> integers <code>nums</code> and a <strong>positive</strong> integer <code>limit</code>.</p>
<p>In one operation, you can choose any two indices <code>i</code> and <code>j</code> and swap <code>nums[i]</code> and <code>nums[j]</code> <stron... | 0 | {
"code": "class Solution {\npublic:\n vector<int> lexicographicallySmallestArray(vector<int>& nums, int limit) {\n int n = nums.size();\n vector<pair<int, int>> sorted(n);\n for(int i = 0; i < n; i++) sorted[i] = {nums[i], i};\n sort(sorted.begin(), sorted.end());\n vector<int> ... |
3,219 | <p>You are given a <strong>0-indexed</strong> array of <strong>positive</strong> integers <code>nums</code> and a <strong>positive</strong> integer <code>limit</code>.</p>
<p>In one operation, you can choose any two indices <code>i</code> and <code>j</code> and swap <code>nums[i]</code> and <code>nums[j]</code> <stron... | 0 | {
"code": "class Solution {\npublic:\n vector<int> lexicographicallySmallestArray(vector<int>& nums, int limit) {\n int n= nums.size();\n vector<pair<int,int>> vec(n);\n for(int i=0;i<n;i++){\n vec[i] = {nums[i],i};\n };\n sort(vec.begin(),vec.end());\n priority... |
3,219 | <p>You are given a <strong>0-indexed</strong> array of <strong>positive</strong> integers <code>nums</code> and a <strong>positive</strong> integer <code>limit</code>.</p>
<p>In one operation, you can choose any two indices <code>i</code> and <code>j</code> and swap <code>nums[i]</code> and <code>nums[j]</code> <stron... | 0 | {
"code": "class Solution {\npublic:\n\tvector<int> lexicographicallySmallestArray(vector<int>& nums, int limit) \n\t{\n\t\tvector<int>soln(nums.size()); \n\n\t\tvector<pair<int, int>>Pairs(nums.size()); \n\t\tfor (int i = 0; i < nums.size(); i++)\n\t\t\tPairs[i] = make_pair(nums[i], i); \n\t\tsort(Pairs.begin(), Pai... |
3,219 | <p>You are given a <strong>0-indexed</strong> array of <strong>positive</strong> integers <code>nums</code> and a <strong>positive</strong> integer <code>limit</code>.</p>
<p>In one operation, you can choose any two indices <code>i</code> and <code>j</code> and swap <code>nums[i]</code> and <code>nums[j]</code> <stron... | 0 | {
"code": "class Solution {\npublic:\n vector<int> lexicographicallySmallestArray(vector<int>& nums, int limit) {\n int n = nums.size();\n vector<int> idx(n);\n vector<int> ordered = nums;\n\n sort(ordered.begin(), ordered.end());\n\n for(int i = 0; i < n; i++) {\n idx... |
3,219 | <p>You are given a <strong>0-indexed</strong> array of <strong>positive</strong> integers <code>nums</code> and a <strong>positive</strong> integer <code>limit</code>.</p>
<p>In one operation, you can choose any two indices <code>i</code> and <code>j</code> and swap <code>nums[i]</code> and <code>nums[j]</code> <stron... | 0 | {
"code": "class Solution {\npublic:\n vector<int> lexicographicallySmallestArray(vector<int>& a, int l) {\n int n=a.size();\n vector <pair <int,int>> p(n);\n for(int i=0;i<n;i++){\n p[i]={a[i],i};\n }\n sort(p.begin(),p.end());\n vector<int> v;\n for(aut... |
3,219 | <p>You are given a <strong>0-indexed</strong> array of <strong>positive</strong> integers <code>nums</code> and a <strong>positive</strong> integer <code>limit</code>.</p>
<p>In one operation, you can choose any two indices <code>i</code> and <code>j</code> and swap <code>nums[i]</code> and <code>nums[j]</code> <stron... | 0 | {
"code": "class Solution {\npublic:\n vector<int> lexicographicallySmallestArray(vector<int>& nums, int limit) {\n std::vector<std::pair<int, int>> num_pos;\n num_pos.reserve(nums.size());\n\n \n for(int i = 0; i < nums.size(); ++i) {\n num_pos.push_back({nums[i], i});\n ... |
3,219 | <p>You are given a <strong>0-indexed</strong> array of <strong>positive</strong> integers <code>nums</code> and a <strong>positive</strong> integer <code>limit</code>.</p>
<p>In one operation, you can choose any two indices <code>i</code> and <code>j</code> and swap <code>nums[i]</code> and <code>nums[j]</code> <stron... | 0 | {
"code": "class Solution {\npublic:\n vector<int> lexicographicallySmallestArray(vector<int>& nums, int l) {\n vector<pair<int,int>>v;\n for(int i=0;i<nums.size();i++){\n v.push_back({nums[i],i}); \n }\n int n=nums.size();\n sort(v.begin(),v.end());\n // vector<int>adj[nums.siz... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.