id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 3 | {
"code": "class Solution {\npublic:\n static const int MOD = 1e9 + 7; // Define the modulo constant\n\n // Store the subtree sums\n unordered_map<TreeNode*, int> subtreeSumMap;\n \n // Helper function to calculate the sum of all nodes in the tree\n int calculateSum(TreeNode* root) {\n if (ro... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 3 | {
"code": "class Solution {\npublic:\n long long q = 0;\n \n long long findmax(map<TreeNode*, long long>& m, TreeNode* root) {\n if (root == nullptr) {\n return 0;\n }\n \n long long leftSum = m[root->left]; // Safe access as NULL returns 0\n long long rightSum ... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,465 | <p>Given the <code>root</code> of a binary tree, split the binary tree into two subtrees by removing one edge such that the product of the sums of the subtrees is maximized.</p>
<p>Return <em>the maximum product of the sums of the two subtrees</em>. Since the answer may be too large, return it <strong>modulo</strong> ... | 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... |
1,469 | <p>You are given two strings of the same length <code>s</code> and <code>t</code>. In one step you can choose <strong>any character</strong> of <code>t</code> and replace it with <strong>another character</strong>.</p>
<p>Return <em>the minimum number of steps</em> to make <code>t</code> an anagram of <code>s</code>.<... | 0 | {
"code": "class Solution {\npublic:\n int minSteps(const string& s, const string& t) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n\n // [char, count]\n std::unordered_map<char, int> sMap;\n\n for (const auto& c: s) {\n ++sMap[c];\n... |
1,469 | <p>You are given two strings of the same length <code>s</code> and <code>t</code>. In one step you can choose <strong>any character</strong> of <code>t</code> and replace it with <strong>another character</strong>.</p>
<p>Return <em>the minimum number of steps</em> to make <code>t</code> an anagram of <code>s</code>.<... | 0 | {
"code": "class Solution {\npublic:\n int minSteps(const string& s, const string& t) {\n // [char, count]\n std::unordered_map<char, int> sMap;\n\n for (const auto& c: s) {\n ++sMap[c];\n }\n\n int count = 0;\n\n for (const auto& c: t) {\n auto findI... |
1,469 | <p>You are given two strings of the same length <code>s</code> and <code>t</code>. In one step you can choose <strong>any character</strong> of <code>t</code> and replace it with <strong>another character</strong>.</p>
<p>Return <em>the minimum number of steps</em> to make <code>t</code> an anagram of <code>s</code>.<... | 0 | {
"code": "class Solution \n{\npublic:\n int minSteps(const string& s, const string& t) \n {\n unordered_map<char, int> freq_s;\n unordered_map<char, int> freq_t;\n int count = 0;\n\n for (const auto& elem : s)\n {\n ++freq_s[elem];\n }\n for (const au... |
1,469 | <p>You are given two strings of the same length <code>s</code> and <code>t</code>. In one step you can choose <strong>any character</strong> of <code>t</code> and replace it with <strong>another character</strong>.</p>
<p>Return <em>the minimum number of steps</em> to make <code>t</code> an anagram of <code>s</code>.<... | 0 | {
"code": "class Solution {\npublic:\n int minSteps(string s, string t) {\n int count[26] = {0};\n for (char c : s) count[c - 'a']++;\n for (char c : t) count[c - 'a']--;\n int steps = 0;\n for (int i = 0; i < 26; ++i) if (count[i] > 0) steps += count[i];\n return steps;\n... |
1,469 | <p>You are given two strings of the same length <code>s</code> and <code>t</code>. In one step you can choose <strong>any character</strong> of <code>t</code> and replace it with <strong>another character</strong>.</p>
<p>Return <em>the minimum number of steps</em> to make <code>t</code> an anagram of <code>s</code>.<... | 0 | {
"code": "class Solution {\npublic:\n int minSteps(string s, string t) {\n int count[26] = {0};\n // Storing the difference of frequencies of characters in t and s.\n for (int i = 0; i < s.size(); i++) {\n count[t[i] - 'a']++;\n count[s[i] - 'a']--;\n }\n\n ... |
1,469 | <p>You are given two strings of the same length <code>s</code> and <code>t</code>. In one step you can choose <strong>any character</strong> of <code>t</code> and replace it with <strong>another character</strong>.</p>
<p>Return <em>the minimum number of steps</em> to make <code>t</code> an anagram of <code>s</code>.<... | 0 | {
"code": "class Solution {\npublic:\n int minSteps(string s, string t) {\n vector<int> sarr(26, 0);\n vector<int> tarr(26, 0);\n \n for(char ch: s) {\n int idx = ch - 'a';\n sarr[idx]++;\n }\n for(char ch: t) {\n int idx = ch - 'a';\n ... |
1,469 | <p>You are given two strings of the same length <code>s</code> and <code>t</code>. In one step you can choose <strong>any character</strong> of <code>t</code> and replace it with <strong>another character</strong>.</p>
<p>Return <em>the minimum number of steps</em> to make <code>t</code> an anagram of <code>s</code>.<... | 0 | {
"code": "class Solution {\npublic:\n int minSteps(string s, string t) {\n int a[27]; int b[27]; int diff = 0;\n for (int i = 1; i <= 26; i++) a[i] = 0; for (int i = 1; i <= 26; i++) b[i] = 0;\n for (int i = 0; i < s.length(); i++) { a[s[i] - 'a' + 1]++; }\n for (int i = 0; i < t.lengt... |
1,469 | <p>You are given two strings of the same length <code>s</code> and <code>t</code>. In one step you can choose <strong>any character</strong> of <code>t</code> and replace it with <strong>another character</strong>.</p>
<p>Return <em>the minimum number of steps</em> to make <code>t</code> an anagram of <code>s</code>.<... | 0 | {
"code": "class Solution {\npublic:\n int minSteps(string s, string t) {\n int vocab [26] = {0}, ans = 0;\n for(int i=0;i<s.length();i++) vocab[s[i]-'a']++, vocab[t[i]-'a']--;\n for(int x:vocab) if(x > 0) ans+=x;\n return ans;\n }\n};",
"memory": "18100"
} |
1,469 | <p>You are given two strings of the same length <code>s</code> and <code>t</code>. In one step you can choose <strong>any character</strong> of <code>t</code> and replace it with <strong>another character</strong>.</p>
<p>Return <em>the minimum number of steps</em> to make <code>t</code> an anagram of <code>s</code>.<... | 1 | {
"code": "class Solution {\npublic:\n int minSteps(string s, string t) {\n vector<int> sCnt(128), tCnt(128);\n for(auto &c:s){\n sCnt[c]++;\n }\n for(auto &c:t){\n tCnt[c]++;\n }\n int tHas=0;\n for(int i=0;i<128;i++){\n tHas+=min(t... |
1,469 | <p>You are given two strings of the same length <code>s</code> and <code>t</code>. In one step you can choose <strong>any character</strong> of <code>t</code> and replace it with <strong>another character</strong>.</p>
<p>Return <em>the minimum number of steps</em> to make <code>t</code> an anagram of <code>s</code>.<... | 2 | {
"code": "class Solution {\npublic:\n int minSteps(string s, string t) {\n int cnt=0;\n set<char>st;\n for(int i=0;i<s.length();i++){\n st.insert(s[i]);\n }\n vector<char> v(st.begin(), st.end());\n for(int i=0;i<v.size();i++){\n int a=count(s.begin(),s.end(),v[i]);\n ... |
1,469 | <p>You are given two strings of the same length <code>s</code> and <code>t</code>. In one step you can choose <strong>any character</strong> of <code>t</code> and replace it with <strong>another character</strong>.</p>
<p>Return <em>the minimum number of steps</em> to make <code>t</code> an anagram of <code>s</code>.<... | 2 | {
"code": "class Solution {\npublic:\n int minSteps(string s, string t) {\n unordered_map<char,int> mp_count;\n\n for(auto &chr : s){\n mp_count[chr]++;\n } \n for(auto &chr : t){\n mp_count[chr]--;\n } \n int total = 0; \n for(auto &pair :... |
1,469 | <p>You are given two strings of the same length <code>s</code> and <code>t</code>. In one step you can choose <strong>any character</strong> of <code>t</code> and replace it with <strong>another character</strong>.</p>
<p>Return <em>the minimum number of steps</em> to make <code>t</code> an anagram of <code>s</code>.<... | 2 | {
"code": "class Solution {\npublic:\n int minSteps(string s, string t) {\n unordered_map<char, int> m;\n \n // Count frequency of characters in s\n for (char a : s) {\n m[a]++;\n }\n \n // Subtract frequency of characters in t\n for (char a : t) {\n m[a]--;\n }\n \n... |
1,469 | <p>You are given two strings of the same length <code>s</code> and <code>t</code>. In one step you can choose <strong>any character</strong> of <code>t</code> and replace it with <strong>another character</strong>.</p>
<p>Return <em>the minimum number of steps</em> to make <code>t</code> an anagram of <code>s</code>.<... | 2 | {
"code": "class Solution {\npublic:\n int minSteps(string s, string t) {\n int count = 0;\n unordered_map<char,int> mp;\n for(auto it:s){\n mp[it]++;\n }\n for(auto it:t){\n if(mp[it]>0){\n mp[it]--;\n count++;\n }\n }\n\n ... |
1,469 | <p>You are given two strings of the same length <code>s</code> and <code>t</code>. In one step you can choose <strong>any character</strong> of <code>t</code> and replace it with <strong>another character</strong>.</p>
<p>Return <em>the minimum number of steps</em> to make <code>t</code> an anagram of <code>s</code>.<... | 2 | {
"code": "class Solution {\npublic:\n int minSteps(string s, string t) {\n unordered_map<char, int> advay;\n int cnt = 0;\n for(int i = 0; i < s.length(); ++i) advay[s[i]]++;\n for(int i = 0; i < t.length(); ++i){\n if (advay.find(t[i]) != advay.end()){\n adva... |
1,469 | <p>You are given two strings of the same length <code>s</code> and <code>t</code>. In one step you can choose <strong>any character</strong> of <code>t</code> and replace it with <strong>another character</strong>.</p>
<p>Return <em>the minimum number of steps</em> to make <code>t</code> an anagram of <code>s</code>.<... | 2 | {
"code": "class Solution {\npublic:\n int minSteps(string s, string t) {\n\n map<char, int> m;\n for(auto a:s)m[a]++;\n for(auto a:t)m[a]--;\n int ans = 0;\n for (auto a : m)ans += abs(a.second);\n return ans/2;\n \n }\n};",
"memory": "19400"
} |
1,469 | <p>You are given two strings of the same length <code>s</code> and <code>t</code>. In one step you can choose <strong>any character</strong> of <code>t</code> and replace it with <strong>another character</strong>.</p>
<p>Return <em>the minimum number of steps</em> to make <code>t</code> an anagram of <code>s</code>.<... | 3 | {
"code": "class Solution {\npublic:\n int minSteps(string s, string t) {\n int res = 0, n = s.size();\n unordered_map<char, int> cnt1, cnt2;\n\n for (int i = 0; i < n; i++) {\n cnt1[s[i]]++;\n cnt2[t[i]]++;\n }\n\n for (int i = 0; i < 26; i++) {\n ... |
1,469 | <p>You are given two strings of the same length <code>s</code> and <code>t</code>. In one step you can choose <strong>any character</strong> of <code>t</code> and replace it with <strong>another character</strong>.</p>
<p>Return <em>the minimum number of steps</em> to make <code>t</code> an anagram of <code>s</code>.<... | 3 | {
"code": "class Solution {\npublic:\n int minSteps(string s, string t) {\n unordered_map<char,int>sfreq;\n unordered_map<char,int>tfreq; \n for(char ch:s){\n sfreq[ch]++;\n }\n for(char ch:t){\n tfreq[ch]++;\n }\n int steps=0;\n \n for(auto &[schar,sc... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 0 | {
"code": "class Solution {\npublic:\n int numOfArrays(int n, int m, int k) {\n if(m < k || k == 0) return 0;\n\n int ans = 0;\n int md = 1e9 + 7;\n int prefSum = 0;\n vector<vector<int>> prev(k + 1, vector<int> (m + 1, 0)), cur(k + 1, vector<int> (m + 1, 0));\n\n for(int ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 0 | {
"code": "class Solution {\npublic:\n int numOfArrays(int n, int m, int k) {\n if(m < k || k == 0) return 0;\n\n int ans = 0;\n int md = 1e9 + 7;\n int prefSum = 0;\n vector<vector<int>> prev(k + 1, vector<int> (m + 1, 0)), cur(k + 1, vector<int> (m + 1, 0));\n\n for(int ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 0 | {
"code": "// class Solution {\n// public:\n// int mod=1e9+7;\n// int dp[51][101][51];\n// int helper(int idx,int search_cost,int maxi, int n,int m,int k){\n// //base case\n// if(idx==n){\n// if(search_cost==k){\n// return 1;\n// }\n// re... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 0 | {
"code": "class Solution {\npublic:\n int N, M, K;\n int mod = 1e9 + 7;\n int t[51][51][101];\n int solve(int idx, int searchCost, int maxSoFar){\n if(idx == N){\n if(searchCost == K){\n return 1;\n }\n return 0;\n }\n if(t[idx][searchC... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 0 | {
"code": "class Solution {\npublic:\n int N, M, K;\n int MOD = 1e9+7;\n int t[51][51][101];\n \n int solve(int idx, int searchCost, int maxSoFar) {\n if(idx == N) {\n if(searchCost == K)\n return 1;\n return 0;\n }\n \n if(t[idx][searchC... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 0 | {
"code": "class Solution {\npublic:\n int N, M, K;\n int MOD = 1e9 + 7;\n int dp[51][51][101];\n \n int solve(int idx, int searchCost, int maxSoFar) {\n if(idx == N) {\n if(searchCost == K) return 1;\n\n return 0;\n }\n \n if(dp[idx][searchCost][maxSoF... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 0 | {
"code": "class Solution {\npublic:\n int N, M, K;\n int dp[51][51][101];\n int mod=1e9+7;\n int solve(int index, int searchcost, int maxfar){\n if(index==N){\n if(searchcost==K){\n return 1;\n }\n else{\n return 0;\n }\n ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 0 | {
"code": "class Solution {\npublic:\n \n int N;\n int M;\n int K;\n const int MOD = 1e9 + 7;\n int dp[51][51][101];\n int solve(int i, int sc ,int maxi){\n if(i == N){\n if(sc ==K){\n return 1;\n }\n return 0;\n }\n if( dp[i][sc][m... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 1 | {
"code": "class Solution {\npublic:\n int t[55][55][105];\n int mod=1e9+7;\n int func(int n,int m,int k,int num){\n if(n==0){\n return k==0;\n }\n if(t[n][k][num+1]!=-1){\n return t[n][k][num+1];\n }\n // if(k==0) return 0;\n int count=0;\n ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 1 | {
"code": "class Solution {\npublic:\n int mod = 1e9+7;\n int M;\n int K;\n int N;\n int dp[55][55][105];\n int solve(int idx, int search_cost, int max_so_far){\n if(idx == N){\n if(search_cost == K){\n return 1;\n }\n return 0;\n }\n ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 1 | {
"code": "class Solution {\npublic:\n int dp[55][105][55];\n int ans(int val,int curr,int cost,int n,int m,int k){\n if(cost>k) return 0;\n if(val==n){\n if(cost==k) return 1;\n else return 0;\n }\n if(dp[val][curr][cost]!=-1) return dp[val][curr][cost];\n ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 1 | {
"code": "//Approach-2 (Bottom Up)\n//T.C : O(NKM^2)\nclass Solution {\npublic:\n /* let ways[i][j][k] = # ways to construct an array of length i with max element equal to j and a search cost of k. */\n long long ways[51][101][51];\n const int MOD = 1e9 + 7;\n \n int numOfArrays(int n, int m, int k) {... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 1 | {
"code": "// Approach-2 (Bottom Up)\n// T.C : O(NKM^2)\nclass Solution {\npublic:\n /* let ways[i][j][k] = # ways to construct an array of length i with max\n * element equal to j and a search cost of k. */\n long long ways[51][101][51];\n const int MOD = 1e9 + 7;\n\n int numOfArrays(int n, int m, in... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 1 | {
"code": "class Solution {\npublic:\n int mod = 1e9+7;\n int dp[51][101][101];\n int solve(int n,int m,int k,int index,int search_cost,int maxi){\n if(index>=n){\n if(search_cost==k){\n return 1;\n }\n return 0;\n }\n if(dp[index][search_c... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "class Solution {\npublic:\n int numOfArrays(int n, int m, int k)\n {\n int kk=k;\n long long dp[n+1][m+1][kk+2];\n int i,j,p;\n long long brr[m+1][kk+2];\n int mod=1e9+7;\n for(i=0;i<=n;i++)\n {\n for(j=0;j<=m;j++)\n {\n ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "class Solution {\npublic:\n int numOfArrays(int n, int m, int k)\n {\n int kk=k;\n long long dp[n+1][m+1][kk+2];\n int i,j,p;\n long long brr[m+1][kk+2];\n int mod=1e9+7;\n for(i=0;i<=n;i++)\n {\n for(j=0;j<=m;j++)\n {\n ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "class Solution {\npublic:\n int numOfArrays(int n, int m, int k)\n {\n int kk=k;\n long long dp[n+1][m+1][kk+2];\n int i,j,p;\n long long brr[m+1][kk+2];\n int mod=1e9+7;\n for(i=0;i<=n;i++)\n {\n for(j=0;j<=m;j++)\n {\n ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "class Solution {\npublic:\n int generate(const int &n, const int &m, const int &k, int i, int score, int maxVal)\n {\n if (i == n)\n {\n if (score == k)\n {\n return 1;\n }\n return 0;\n }\n int answer = 0;\n ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "class Solution {\n public:\n const int mod=int(1e9+7);\n public:\n int solve(int len,int maxsofar,int lastmax,int n,int m,int k,vector<vector<vector<int>>> &dp){\n if(len==n){\n if(maxsofar==k) return 1;\n return 0;\n }\n //if(maxsofar==k+1) return 0;\n if(dp[len][maxs... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "class Solution {\npublic:\n int generate(const int &n, const int &m, const int &k, int i, int score, int maxVal)\n {\n if (i == n)\n {\n if (score == k)\n {\n return 1;\n }\n return 0;\n }\n int answer = 0;\n ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "class Solution {\npublic:\n int generate(const int &n, const int &m, const int &k, int i, int score, int maxVal)\n {\n if (i == n)\n {\n if (score == k)\n {\n return 1;\n }\n return 0;\n }\n int answer = 0;\n ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<vector<int>>> dp;\n int combination(int &m,int n,int k,int max_val){\n if(k<0) return 0;\n if(n==0){\n if(k==0) return 1;\n return 0;\n }\n if(dp[k][n][max_val]!=-1) return dp[k][n][max_val];\n int ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "using ll=long long int;\nclass Solution {\npublic:\n ll dp[55][105][105];\n ll mod=1e9+7;\n int solve(int curr,int m,int k,int n,int maxi,int score){\n if(curr>=n){\n return (score!=k)?0:1;\n \n }\n if(dp[curr][maxi][score]!=-1)return dp[curr][maxi][score... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "class Solution {\npublic:\n int t[52][152][152];\n int d=1e9+7;\n int solve(int n,int prev,int m, int k)\n {\n if(k<0)\n return 0;\n\n if(n<=0)\n {\n if(k<=0)\n return 1;\n\n return 0;\n }\n\n if(t[n][prev+1][k]!=-1)\n ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "using ll=long long int;\nclass Solution {\npublic:\n ll dp[55][105][105];\n ll mod=1e9+7;\n int solve(int curr,int m,int k,int n,int maxi,int score){\n if(curr==n){\n return (score==k)?1:0;\n \n }\n if(dp[curr][maxi][score]!=-1)return dp[curr][maxi][score... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "class Solution {\npublic:\n using ll = long long;\n static const int N = 55;\n static const int M = 105;\n ll dp[N][M][N];\n ll pre[N][M][N];\n // pre[i][j][k] = dp[i][1][k] + dp[i][2][k] + ... + dp[i][j-1][k] + dp[i][j][k]\n int numOfArrays(int n, int m, int k) {\n const int MO... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "class Solution {\npublic:\n int mod = 1e9+7;\n vector<vector<vector<int>>> dp;\n int rec(int index, int prev, int m, int k, int n) {\n if(k < 0) return 0;\n if(index == n && !k) return 1;\n if(index == n) return 0;\n if(dp[index][prev][k] != -1) return dp[index][prev][k... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "class Solution {\npublic:\n int mod = 1e9+7;\n int f(int n, int mx, int k,int m,vector<vector<vector<int>>>&dp){\n if(n==0&&k==0)return 1;\n if(n<0||k<0)return 0;\n if(dp[n][mx][k]!=-1)return dp[n][mx][k];\n int ans = 0;\n for(int i=1;i<=m;i++){\n if(i<=m... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "class Solution {\npublic:\n\n int mod = 1e9+7;\n\n int solve(int index,int maxVal,int currCost,int& n,int& m,int& k,vector<vector<vector<int>>>& dp){\n if(index == n){\n if(currCost == k) return 1;\n return 0;\n }\n if(currCost > k) return 0;\n if(dp[... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "class Solution {\n public:\n int numOfArrays(int n, int m, int k) {\n constexpr int kMod = 1'000'000'007;\n // dp[i][j][k] := the number of ways to build an array of length i, where j\n // is the maximum number and k is `search_cost`\n vector<vector<vector<int>>> dp(\n n + 1, vector<vec... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "class Solution {\npublic:\n const int MOD=1e9 +7;\n int solve(int ind, int currMax, int currCost,int n, int m, int k,vector<vector<vector<int>>>& dp ){\n \n if(currCost>k)return 0;\n if(ind == n){\n if(currCost == k){\n return 1;\n }return 0;\... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 2 | {
"code": "class Solution {\npublic:\n const int MOD=1e9 +7;\n int solve(int ind, int currMax, int currCost,int n, int m, int k,vector<vector<vector<int>>>& dp ){\n \n if(currCost>k)return 0;\n if(ind == n){\n if(currCost == k){\n return 1;\n }return 0;\... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n const int MOD = 1e9 + 7;\n int solve(int i, int maxi, int cost, vector<vector<vector<int>>>& dp, int n,\n int m, int k) {\n if (i == n)\n return cost == k ? 1 : 0;\n if (cost > k)\n return 0;\n if (dp[i][maxi][cost] !... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "#define M 1000000007\nclass Solution {\npublic:\nint solve(int i,int n,int m,int cost,int k,int maxi, vector<vector<vector<int>>>&dp){\n if(cost>k)return 0;\n if(i==n){\n if(cost==k)return 1;\n else return 0;\n }\n if(dp[i][cost][maxi]!=-1)return dp[i][cost][maxi];\n int ans=0;\n for(i... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "#define M 1000000007\nclass Solution {\npublic:\nint solve(int i,int n,int m,int cost,int k,int maxi, vector<vector<vector<int>>>&dp){\n if(cost>k)return 0;\n if(i==n){\n if(cost==k)return 1;\n else return 0;\n }\n if(dp[i][cost][maxi]!=-1)return dp[i][cost][maxi];\n int ans=0;\n for(i... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "#define M 1000000007\nclass Solution {\npublic:\nint solve(int i,int n,int m,int cost,int k,int maxi, vector<vector<vector<int>>>&dp){\n if(cost>k)return 0;\n if(i==n){\n if(cost==k)return 1;\n else return 0;\n }\n if(dp[i][cost][maxi]!=-1)return dp[i][cost][maxi];\n int ans=0;\n for(i... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n int numOfArrays(int n, int m, int k) {\n vector<vector<vector<int>>> dp(n+1,vector<vector<int>>(m+1,vector<int>(k+1,-1)));\n int mod=1e9+7;\n function<int(int,int,int)> solve = [&](int curr, int maxi, int cost){\n if(cost>k) return 0;\n ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n const int mod = 1e9 + 7;\n \n int numOfArraysHelper(int idx, int lastMax, int k, int n, int m, vector <vector <vector <int>>> &dp) {\n if(idx == n)return !k;\n if(k < 0)return 0;\n if(lastMax > -1 && dp[idx][lastMax][k] != -1)return dp[idx][lastMax]... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n int N ,M ,K;\n int MOD = 1000000007;\n int solve(int idx , int SearchCost , int maxSoFar , vector<vector<vector<int>>>&dp){\n if(idx >= N){\n if(SearchCost == K){\n return 1;\n }\n return 0;\n }\n\n if... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n\n // Approch - \n // We need to construct a array in striclly incressing order means when we get a new element whos greater than the maximum_value/ maxSoFar we increment the SearchCost and we want a array whos search cost is equal to k and the array element have only 1... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n #define ll long long\n #define mod (ll)(1e9 + 7)\n ll solve(int i, int &n, int &m, int k, int curr_max, vector<vector<vector<ll>>> &dp)\n {\n if(i == n)\n return (k == 0);\n\n if(k < 0) return 0;\n\n if(dp[i][k][curr_max] != -1)\n ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "const int mod = 1e9+7;\nclass Solution {\npublic:\n int nTmp, mTmp, kTmp;\n vector<vector<vector<int>>> dp;\n int recur(int i, int prevMax=0, int cost=0){\n if(cost > kTmp) return 0;\n if(i == nTmp) return cost == kTmp;\n if(dp[i][prevMax][cost] != -1) return dp[i][prevMax][co... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n int numOfArrays(int n, int m, int k) {\n if (k == 0) return 0;\n int mod = 1e9 + 7;\n using ll = long long;\n vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(k + 1, vector<ll>(m + 1)));\n for (int i = 1; i <= m; ++i) dp[1][1][i] = 1;... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n const int mod = 1e9+7;\n int numOfArrays(int n, int m, int k) {\n vector<vector<vector<long>>> dp(n, vector<vector<long>>(k+1, vector<long>(m+1,0)));\n //initialize\n for (int p=1; p<=m; p++) dp[0][1][p] = 1;\n //percolate\n for (int i=1;... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n\n/*\nState: f(ind, rem, prev)\n\n- total no of combinations of array that can be created from index: ind to n-1, such that we need to place 'rem' SI elements (i.e cover up a score of rem) && prev max element placed is 'prev' (i.e prev element for which score++ occured is 'prev')... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\nint M = 1e9 + 7;\n int solve(int i,int prev,int k,int n,int m,vector<vector<vector<int>>> &dp){\n if(i == n) return k == 0;\n if(dp[i][prev][k] != 1e9) return (dp[i][prev][k])%M;\n int take = 0;\n for(int f = 1;f<=m;f++){\n if((prev == m+... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n int N;\n int dp[51][200][200];\n int mod=1e9+7;\n int solve(int i,int m,int k,int last)\n {\n if(i==N)\n {\n if(k==0)\n return 1;\n else\n return 0;\n\n ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n int mod=1e9+7;\n long long int helper(vector<vector<vector<long long int>>>&dp , int indx , int maxi , int op , int n , int m , int k) {\n if (indx==n) {\n return (op==k);\n }\n if (op>k) {\n return 0;\n }\n if (dp[i... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "#define ll long long\n#define mod 1000000007\nclass Solution {\npublic:\n // int f(int ind,int maxVal,int k){\n // cout<<ind<<\" \"<<maxVal<<\" \"<<k<<\"\\n\";\n // if(ind==gn)\n // return k==0?1:0;\n // if(k<0)\n // return 0;\n // int ansr=0;\n // an... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n long long mod = 1e9 + 7;\n long long findMultipleUptoNextI(int size, long long num) {\n long long result = 1;\n while(size--) {\n result *= num%mod;\n result %= mod;\n }\n return result%mod;\n }\n long long solve(int&... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n int mod = 1000000007;\n\n long long modExp(long long base, int exp) {\n long long result = 1;\n while (exp > 0) {\n if (exp % 2 == 1) {\n result = (result * base) % mod;\n }\n base = (base * base) % mod;\n ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\n\n int MOD = 1e9+7;\n int f(int idx, int m, int n, int search_cost, int maxSoFar, \n int k, vector<vector<vector<int>>>&dp){\n //base case\n if(idx==n){\n if(search_cost==k){\n return 1;\n }\n ... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n int mod=1e9+7;\n long long solve(int ind,int maxi,int rem,int n,int m,vector<vector<vector<long long>>>&dp){\n if(ind==n){\n if(rem==0){\n return 1;\n }\n return 0;\n }\n if(rem<0){\n return 0;... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n int mod=1e9+7;\n long long solve(int ind,int maxi,int rem,int n,int m,vector<vector<vector<long long>>>&dp){\n if(ind==n){\n if(rem==0){\n return 1;\n }\n return 0;\n }\n // if(rem<0){\n // ret... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n int mod=1e9+7;\n long long solve(int ind,int maxi,int rem,int n,int m,vector<vector<vector<long long>>>&dp){\n if(ind==n){\n if(rem==0){\n return 1;\n }\n return 0;\n }\n if(rem<0){\n return 0;... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "#define mod 1000000007\n\nclass Solution {\npublic:\n // Lambda function to optimize I/O operations\n bool init = []() {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n return true;\n }();\n \n vector<vector<vector<int>>> dp;\n int f(in... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "#define mod 1000000007\n\nclass Solution {\npublic:\n // Lambda function to optimize I/O operations\n bool init = []() {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n return true;\n }();\n \n vector<vector<vector<int>>> dp;\n\n // Hel... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n int numOfArrays(int n, int m, int k) {\n // dp[a][b][c] = number of ways to have a length with max b and cost c\n // dp[a][b][c] => \n // +=1 on dp[a+1][b+1...m][c+1]\n // +=b on dp[a+1][b][c]\n vector<vector<vector<long long>>> dp(n+1... |
1,535 | <p>You are given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
<p>You should build the arr... | 3 | {
"code": "class Solution {\npublic:\n int MOD=1e9+7;\n int fun(int ind, int n, int m, int k, int curr_k, int maxi,vector<vector<vector<long long>>>&dp){\n if(ind ==n){\n if(curr_k==k) return 1;\n return 0;\n }\n if(dp[ind][curr_k][maxi]!=-1) return dp[ind][curr_k][max... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.