id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,346 | <p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
<ul>
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
<li>It consists of only one unique digit.</li>
</ul>
<p>Return <em>t... | 2 | {
"code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n string s=\"\";\n int n=num.size();\n \n for(int i=0;i<n-2;i++){\n if(num[i]==num[i+1] && num[i+1]==num[i+2]){\n string t=\"\";\n for(int j=0;j<3;j++) t+=num[i];\n ... |
2,346 | <p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
<ul>
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
<li>It consists of only one unique digit.</li>
</ul>
<p>Return <em>t... | 2 | {
"code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n string maxGoodInteger = \"\"; // Initialize an empty string to track the largest good integer.\n\n // Iterate through the string, checking each substring of length 3\n for (int i = 0; i <= num.size() - 3; i++) {\n //... |
2,346 | <p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
<ul>
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
<li>It consists of only one unique digit.</li>
</ul>
<p>Return <em>t... | 2 | {
"code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n int n = num.length();\n std::string maksi; // Store the largest good integer as a string\n for (int i = 0; i < n - 2; ++i) {\n // Check if three consecutive characters are the same\n if (num[... |
2,346 | <p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
<ul>
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
<li>It consists of only one unique digit.</li>
</ul>
<p>Return <em>t... | 3 | {
"code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n string res = \"\";\n string maxi = \"0\";\n int n = num.size();\n for(int i = 0; i < n - 2; i++){\n if(num[i] == num[i + 1] && num[i] == num[i + 2])\n maxi = max(maxi, num.substr(i... |
2,346 | <p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
<ul>
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
<li>It consists of only one unique digit.</li>
</ul>
<p>Return <em>t... | 3 | {
"code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n string maxi = \"0\";\n int n = num.size();\n for(int i = 0; i < n - 2; i++){\n if(num[i] == num[i + 1] && num[i] == num[i + 2])\n maxi = max(maxi, num.substr(i,3));\n }\n\n ... |
2,346 | <p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
<ul>
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
<li>It consists of only one unique digit.</li>
</ul>
<p>Return <em>t... | 3 | {
"code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n int n = num.size();\n string ans = \"\";\n for (int i = 0; i < n - 1; i++)\n {\n int a = 0;\n string cnt = \"\";\n int j = i;\n while (j < i + 3)\n {\n... |
2,346 | <p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
<ul>
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
<li>It consists of only one unique digit.</li>
</ul>
<p>Return <em>t... | 3 | {
"code": "class Solution {\npublic:\n string largestGoodInteger(string s) {\n int i=0,j=0;\n int n=s.size();\n int res=0;\n bool say=false;\n while(j<n && i<n && i<=j){\n if(s[i]==s[j]){\n j++;\n if(j-i+1==3 && s[i]==s[j]){\n ... |
2,346 | <p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
<ul>
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
<li>It consists of only one unique digit.</li>
</ul>
<p>Return <em>t... | 3 | {
"code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n set<string> strSet {\"999\",\"888\", \"777\", \"666\", \"555\", \"444\", \"333\", \"222\", \"111\", \"000\"};\n string result = \"\";\n for (int i = 0; i < num.size(); ++i) {\n const string curr = num.s... |
2,346 | <p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
<ul>
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
<li>It consists of only one unique digit.</li>
</ul>
<p>Return <em>t... | 3 | {
"code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n deque<int> window{};\n window.push_back(num[0] - '0');\n window.push_back(num[1] - '0');\n array<bool, 10> candidates{};\n for (size_t i{2}; i < num.size(); ++i) {\n window.push_back(num[i... |
2,346 | <p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
<ul>
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
<li>It consists of only one unique digit.</li>
</ul>
<p>Return <em>t... | 3 | {
"code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n\n int ans = -1; // to store what chars merge into\n string strAns = \"\"; // to store the value to return\n for (int i = 2; i < num.size(); ++i) { // go through from the third\n if (num[i] == num[i - 1... |
2,346 | <p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
<ul>
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
<li>It consists of only one unique digit.</li>
</ul>
<p>Return <em>t... | 3 | {
"code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n int ans = -1; // to store what chars merge into\n string strAns = \"\"; // to store the value to return\n for (int i = 2; i < num.size(); ++i) { // go through from the third\n if (num[i] == num[i - 1] &... |
2,346 | <p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
<ul>
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
<li>It consists of only one unique digit.</li>
</ul>
<p>Return <em>t... | 3 | {
"code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n\n int ans = -1; // to store what chars merge into\n string strAns = \"\"; // to store the value to return\n for (int i = 2; i < num.size(); ++i) { // go through from the third\n if (num[i] == num[i - 1... |
2,346 | <p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
<ul>
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
<li>It consists of only one unique digit.</li>
</ul>
<p>Return <em>t... | 3 | {
"code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n int ans = -1; \n string strAns = \"\"; \n for (int i = 2; i < num.size(); ++i) { \n if (num[i] == num[i - 1] && num[i-1] == num[i - 2]) { \n string sub = num.substr(i - 2, 3); \n ... |
2,346 | <p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
<ul>
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
<li>It consists of only one unique digit.</li>
</ul>
<p>Return <em>t... | 3 | {
"code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n int ans = -1;\n for(int i = 0; i < num.size() - 2; i++) {\n string curr = \"\";\n char loc1 = num[i];\n char loc2 = num[i + 1];\n char loc3 = num[i + 2];\n\n if(loc1... |
2,346 | <p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
<ul>
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
<li>It consists of only one unique digit.</li>
</ul>
<p>Return <em>t... | 3 | {
"code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n int ans = -1;\n for(int i = 0; i < num.size() - 2; i++) {\n string curr = \"\";\n char loc1 = num[i];\n char loc2 = num[i + 1];\n char loc3 = num[i + 2];\n\n if(loc1... |
2,346 | <p>You are given a string <code>num</code> representing a large integer. An integer is <strong>good</strong> if it meets the following conditions:</p>
<ul>
<li>It is a <strong>substring</strong> of <code>num</code> with length <code>3</code>.</li>
<li>It consists of only one unique digit.</li>
</ul>
<p>Return <em>t... | 3 | {
"code": "class Solution {\npublic:\n string largestGoodInteger(string num) {\n int n=num.size();\n if(n==3 ) {\n if(num[0]==num[1] && num[0]==num[2]) return num;\n } \n vector<int> count;\n string temp=\"\";\n for(int i=2;i<n;i++){\n if(num[i]==num... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 2 | {
"code": "auto init = []() {cin.tie(0); ios::sync_with_stdio(0); return 1;}();\nclass Solution {\npublic:\n int ans = 0;\n\n pair<int, int> solve(TreeNode* root) {\n if (!root) return {0, 0};\n\n pair<int, int> left = solve(root->left);\n pair<int, int> right = solve(root->right);\n\n ... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "class Solution {\npublic:\n int countMatchingAverages(TreeNode* root, int& res) {\n if (root == nullptr)\n return 0;\n\n int leftSum = 0, leftCount = 0;\n int rightSum = 0, rightCount = 0;\n\n if (root->left) {\n leftCount = countMatchingAverages(root->l... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "class Solution {\npublic:\n int averageOfSubtree(TreeNode* root) {\n return f(root)[2];\n }\n \n array<int,3> f(TreeNode* root){\n array<int,3> res={root->val,1,0};\n for(TreeNode* ptr:vector<TreeNode*>{root->left,root->right}){\n if(ptr==nullptr) continue;\n ... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "class Avg{\n public:\n int sum,count;\n Avg(int s =0 ,int c = 0){\n sum =s;\n count =c;\n }\n};\nclass Solution {\npublic:\n Avg* GetAvg(TreeNode* root,int &COUNT)\n {\n if(root==nullptr)\n return new Avg();\n int count = 0;\n int sum = 0;\n ... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "\nclass Solution \n{\n public:\n\n map<int, int >mp;\n map<int, vector<int> >avg;\n \n int counter(TreeNode *root)\n {\n if(root==NULL)\n {\n return 0;\n }\n\n if(root && root->left==NULL && root->right==NULL)\n {\n int z=root->val;... |
2,347 | <p>Given the <code>root</code> of a binary tree, return <em>the number of nodes where the value of the node is equal to the <strong>average</strong> of the values in its <strong>subtree</strong></em>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>The <strong>average</strong> of <code>n</code> elements is the <strong>su... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 0 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long maxi=0;\n int n=nums.size();\n int maxele=*max_element(nums.begin(),nums.end());\n int maxcount=0;\n int i=0;\n for(int j=0;j<n;j++){\n if(nums[j]==maxele){\n... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 0 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int start=0,end=0,maxElem=0;\n for(int i=0;i<nums.size();i++){\n maxElem=max(maxElem,nums[i]);\n }\n long long total=0,cnt=0;\n while(end<nums.size()){\n if(nums[en... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 0 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n=nums.size();\n long long countMax=0;\n long long result=0;\n int max_value=*max_element(nums.begin(),nums.end());\n int j=0,i=0;\n while(j<n){\n if(nums[j]==max_v... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 0 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n = nums.size(), maxi = *max_element(nums.begin(), nums.end());\n int i = 0, j = 0, count = 0;\n long long ans = 0;\n while (j < n) {\n if (nums[j] == maxi) count++;\n ... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 0 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int maxElement = *max_element(nums.begin(), nums.end());\n long long ans = 0, l = 0;\n\n for (int r = 0; r < nums.size(); r++) {\n if (nums[r] == maxElement) {\n k--;\n ... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int max_num = 0;\n for(int i = 0; i < nums.size(); ++i){\n if(max_num < nums[i]){\n max_num = nums[i];\n }\n }\n vector<int> cnts(k + 1);\n long long... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n // 1 3 2 3 3\n // i j\n // \n int maxi = *max_element(nums.begin(),nums.end());\n\n int ind = -1;\n\n vector<int> index;\n int cnt = 0;\n long long ans = 0;\n ... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n // 1 3 2 3 3\n // i j\n // \n int maxi = *max_element(nums.begin(),nums.end());\n\n int ind = -1;\n\n vector<int> index;\n int cnt = 0;\n long long ans = 0;\n ... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int max_ele=INT_MIN,n=nums.size();\n for(int i=0;i<n;i++){\n max_ele=max(max_ele,nums[i]);\n }\n long long start=0,end=0,count=0;\n unordered_map<int,int>m;\n while(end... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int maxi = INT_MIN;\n for(int i=0; i<nums.size(); i++){\n if(nums[i] > maxi) maxi = nums[i];\n }\n int l =0;\n int r =0;\n unordered_map<int, int> mp;\n long lo... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "class Solution {\npublic:\n long long yes(vector<int>& nums, int k,int maxi){\n unordered_map<int,int> m;\n int l=0,r=0;\n long long cnt=0;\n while(r<nums.size()){\n if(nums[r]==maxi) m[maxi]++;\n while(m[maxi]>=k){\n if(nums[l]==maxi) m[m... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "class Solution {\npublic:\n long long yes(vector<int>& nums, int k,int maxi){\n unordered_map<int,int> m;\n int l=0,r=0;\n long long cnt=0;\n while(r<nums.size()){\n if(nums[r]==maxi) m[maxi]++;\n while(m[maxi]>=k){\n if(nums[l]==maxi) m[m... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int sz = nums.size();\n int max_ele = *max_element(nums.begin(), nums.end());\n queue<int> indices;\n\n long long subCount = 0;\n\n for(int i = 0; i < sz; i++) {\n if(nums[i] ... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n // int ans = 0;\n int maxi = 0;\n int n = nums.size();\n for(int i=0;i<n;i++){\n maxi=max(maxi,nums[i]);\n }\n queue<int>q;\n long long ans = 0;\n for(int... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long ans = 0;\n int maxNum = nums[0];\n for (int num: nums) {\n maxNum = max(num, maxNum);\n }\n\n // keep track of indices where k appears\n queue<int> indices;\n... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long ans = 0;\n int max_n = nums[0];\n for(auto i:nums)\n if(i>max_n)\n max_n = i;\n\n std::queue<int> q;\n for(int i=0; i<nums.size(); i++){\n ... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "#pragma GCC optimize(\"O3\",\"unroll-loops\")\n\nclass Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long ans = 0;\n int max_n = *max_element(nums.begin(),nums.end());\n std::queue<int> q;\n for(int i=0; i<nums.size(); i++){\n if... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long ans = 0;\n int max_n = *max_element(nums.begin(),nums.end());\n std::queue<int> q;\n for(int i=0; i<nums.size(); i++){\n if(nums[i]==max_n)\n q.push(i);\n ... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "#include <climits>\n#include <vector>\n\nclass Solution {\n public:\n long long countSubarrays(std::vector<int>& nums, int k) {\n // Constraints:\n // - k is never smaller than 1.\n // - nums is never empty.\n // Traverse to find largest number.\n int largestNumber = INT_MIN;\n int numOc... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "#include <climits>\n#include <vector>\n\nclass Solution {\n public:\n long long countSubarrays(std::vector<int>& nums, int k) {\n // Constraints:\n // - k is never smaller than 1.\n // - nums is never empty.\n // Traverse to find largest number.\n int largestNumber = INT_MIN;\n int numOc... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "#include <climits>\n#include <vector>\n\nclass Solution {\n public:\n long long countSubarrays(std::vector<int>& nums, int k) {\n // Constraints:\n // - k is never smaller than 1.\n // - nums is never empty.\n // Traverse to find largest number.\n int largestNumber = INT_MIN;\n int numOc... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int mx = *max_element(nums.begin(), nums.end());\n vector<int> lct;\n long long ans = 0;\n for (int i = 0; i < nums.size(); i++){\n if (nums[i] == mx) lct.push_back(i);\n ... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int max_elem =-1;\n for(int num:nums){\n max_elem = max(max_elem,num);\n }\n long long ans =0;\n vector<int> idx_hold;\n int cnt =0;\n int n = nums.size();\n ... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int max=nums[0];\n int n=nums.size();\n for(int i=1;i<n;i++)\n if(max<nums[i]) max=nums[i];\n vector<int> max_index;\n max_index.push_back(-1);\n for(int i=0;i<n;i++)\n ... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int N = (int)nums.size();\n int max_value = *max_element(nums.begin(), nums.end());\n vector<int> positions;\n for (int i = 0; i < N; i++) {\n if (nums[i] == max_value) {\n ... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n //gyaan waali baatein\n //ki bhai issse pehle wala approach me hmlog piche se jitna subarray\n //bn rha tha wo nikal liye \n //or es baar hmlog aage se jo bhi subarray bn skta hai wo nikaal rhe... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n=nums.size();\n int maxi = *max_element(nums.begin(),nums.end());\n vector<int> temp;\n for(int i=0;i<n;i++){\n if(nums[i]==maxi){\n temp.push_back(i);\n ... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int maxnum = *max_element(begin(nums), end(nums));\n long long ans = 0;\n int n = nums.size();\n\n vector<int> maxind(1,-1);\n for (int i = 0; i < n; i++) {\n if (nums[i] == m... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n deque<long long>dq;\n int mx = *max_element(nums.begin(),nums.end());\n long long count = 0;\n for (int i=0; i<n;i++) {\n if (nums[i] == mx) dq.push_bac... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long s=0,e=0,i=0, ans=1;\n int maxi=INT_MIN;\n queue<long long> q;\n for(int i=0;i<nums.size();i++){\n maxi=max(maxi,nums[i]);\n }\n\n while(e<nums.size()){\n ... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 3 | {
"code": "class Solution {\nprivate:\n vector<int> prefixSum;\n int n, k, maxElement;\n \n long long countSubarraysRecursive(int start, int end) {\n if (start > end) return 0;\n if (start == end) return (prefixSum[end + 1] - prefixSum[start] >= k) ? 1 : 0;\n \n int mid = start... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n vector<int>temp=nums;int n=nums.size();\n int freq=0;\n sort(temp.begin(),temp.end());\n int large=temp[temp.size()-1];\n int l=0;long long max=0;int r=0;\n for(int i=0;i<nums.siz... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n vector<int>temp=nums;int n=nums.size();\n int freq=0;\n sort(temp.begin(),temp.end());\n int large=temp[temp.size()-1];\n int l=0;long long max=0;int r=0;\n for(int i=0;i<nums.siz... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n \n long long answer = 0;\n \n queue<int> numbers;\n int N = nums.size();\n int maxElement = -1;\n \n for(auto num: nums){\n maxElement = max(maxElement, n... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int p=INT_MIN;\n for(int t:nums)\n {\n p=max(p,t);\n }\n vector<long long int>vec1;\n for(int i=0;i<nums.size();i++)\n {\n if(nums[i]==p)\n vec1.push_back(i);\n ... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n // long long l = 0;\n // long long r = 0;\n // long long n =nums.size();\n // long long count = 0;\n // long long res = 0;\n // long long max_ele = *max_element(nums.begin(), nums... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n using ll = long long;\n int mael = -1;\n for(auto e : nums) mael = max(mael, e);\n vector<ll> occ;\n ll t = 0;\n for(ll i = 0; i < nums.size(); i++) {\n if (nums[i] == ... |
3,213 | <p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p>
<p>Return <em>the number of subarrays where the <strong>maximum</strong> element of </em><code>nums</code><em> appears <strong>at least</strong> </em><code>k</code><em> times in that subarray.</em></p>
<p>A... | 3 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n vector<long long int> maxi;\n long long int m = -1;\n for(auto it: nums){\n m=max(m, (long long)it);\n }\n for(int i=0;i<nums.size();i++){\n if(nums[i]==m){\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.