id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n std::vector<std::string> removeInvalidParentheses(std::string s) {\n GenerateParentheses(s, \"\", 0);\n\n std::vector<std::string> res;\n for (auto str : map.begin()->second) {\n res.push_back(std::move(str));\n }\n\n return res;\...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\n unordered_map<string,bool> dp;\n int validatePrenthesis(string &s){\n int n = s.size();\n stack<char> st;\n int count = 0;\n for(int i=0;i<n;i++){\n if(s[i] == '('){\n st.push('(');\n }else if(s[i] == ')'){\n if(!st....
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n unordered_map<int, set<string>> allPossibilities;\n int minRemove = INT_MAX;\n\n void search(int idx, string&s, int balance, int removes, string wip) {\n if (idx == s.size()-1){\n if (s[idx] == '('){\n if (balance == 0){\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n\nvoid solve(string str, int mra, set<string>&st, map<string,bool>&mp)\n{\n if(mra==0)\n {\n int mrnow=getMinRemovals(str);\n if(mrnow==0)\n {\n st.insert(str);\n return;\n }\n }\n if(mp[str]) return;\n mp[str]=true...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n void check(set<string>& result, const string& s, int pos, int open, int removals) {\n int len = s.length();\n // skip all non-brackets\n while (pos < len && s[pos] != '(' && s[pos] != ')') { \n pos++;\n }\n if (pos == len) {\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n void check_mem_exceeded(set<string>& result, const string& s, int pos, int open, vector<int> removals) {\n int len = s.length();\n // skip all non-brackets\n while (pos < len && s[pos] != '(' && s[pos] != ')') { \n pos++;\n }\n if...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<string> removeInvalidParentheses(string s) {\n \n int total = 0;\n for (char c : s) total += (c == '(' || c == ')');\n \n int removals = minimumRemovals(s);\n \n if (removals == 0) return {s};\n \n unordere...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<string> removeInvalidParentheses(string s) {\n \n int total = 0;\n for (char c : s) total += (c == '(' || c == ')');\n \n int removals = minimumRemovals(s);\n \n if (removals == 0) return {s};\n \n unordere...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<string> removeInvalidParentheses(string s) {\n \n int total = 0;\n for (char c : s) total += (c == '(' || c == ')');\n \n int removals = minimumRemovals(s);\n \n if (removals == 0) return {s};\n \n unordere...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n bool check(string& s){\n stack<char>s1;\n for(int i=0;i<s.size();i++){\n if(s[i]==')'){\n while(s1.size() && s1.top()!='('){\n s1.pop();\n }\n if(s1.size() && s1.top()=='('){\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n int isValid(string s)\n {\n stack<char> st;\n for(int i = 0;i < s.size();i++)\n {\n if(s[i] != '(' && s[i] != ')')\n continue;\n if(s[i] == '(')\n st.push('(');\n else\n {\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "const int INF = 1e9 + 5;\n\nbool valid(string &str){\n stack<int> s;\n int n = str.size();\n for(int i = 0; i < n; i++){\n if(str[i] == '('){\n s.push('(');\n }\n else if(str[i] == ')'){\n if(s.empty()){\n return false;\n }\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<string> removeInvalidParentheses(string s) {\n vector<pair<string, int>> res;\n res.push_back({\"\",0});\n for (int i = 0; i < s.size(); ++i)\n {\n vector<pair<string, int>> newp;\n for (auto& p : res )\n {\n...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n std::set<std::string> ans;\n int minDeletions = INT_MAX;\n bool isValid(const std::string &str) {\n int balance = 0;\n for (char c : str) {\n if (c == '(') ++balance;\n if (c == ')') --balance;\n if (balance < 0) return fal...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "\nclass Solution {\nprivate:\n int isValid(string& s) {\n stack<char> st;\n\n for (char c : s) {\n if(c == '(') st.push(c);\n else if(c == ')') {\n if(!st.empty() && st.top() == '(') st.pop();\n else st.push(c);\n }\n }\...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n unordered_set<string>st;\n int len;\n vector<string> removeInvalidParentheses(string s) {\n len=s.length();\n vector<string>ans;\n int open=0,close=0;\n int c=0;\n stack<char>stk;\n for(int i=0;i<s.length();i++)\n {\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n bool isValid(string &s){\n stack<char> st;\n for(int i=0;i<s.size();i++){\n if(s[i] == ')'){\n if(!st.empty() && st.top() == '(')\n st.pop();\n else\n return 0; \n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n bool isValid(string &s){\n stack<char> st;\n for(int i=0;i<s.size();i++){\n if(s[i] == ')'){\n if(!st.empty() && st.top() == '(')\n st.pop();\n else\n return 0; \n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n void combStep(int idx, string& curr, set<string>& res, string &s, int cutCount) {\n if (curr.size() == s.size() - cutCount) {\n if (isValid(curr)) {\n res.insert(curr); \n }\n return;\n }\n fo...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n unordered_set<string> set;\n vector<string> ans;\n int len;\n\n bool isValid(string str){\n stack<char> st;\n for(int i = 0; i < str.length(); i++){\n if(str[i] == '('){\n st.push(str[i]);\n }\n else if(st...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<string> removeInvalidParentheses(string s) {\n int removeCount = checkoutInvalid(s);\n DFS(s, removeCount, s, 0);\n return vector<string>(ans.begin(), ans.end());\n }\nprivate:\n set<string> ans;\n int checkoutInvalid(string s) {\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution\n{\n int helper(string &s)\n {\n stack<char> s1;\n int count = 0;\n for (auto &it : s)\n {\n if (it == ')')\n {\n while (!s1.empty() && s1.top() != '(')\n {\n s1.pop();\n }...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<string> ans;\n int minRemoval = 0;\n unordered_map <string, bool> isExist;\n\n void handle(string s, int i, int n, string curStr, int curSum) {\n if (i == n) {\n if (curSum == 0 && curStr.size() + minRemoval == n) {\n if (!isEx...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "#pragma GCC optimize(\"O3\")\n#pragma GCC optimize(\"unroll-loops\")\nstatic const int _ = []() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); return 0; }();\n\nclass Solution {\npublic:\n vector<string> removeInvalidParentheses(string s) {\n int n = s.size();\...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "#pragma GCC optimize(\"O3\")\n#pragma GCC optimize(\"unroll-loops\")\nstatic const int _ = []() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); return 0; }();\n\nclass Solution {\npublic:\n vector<string> removeInvalidParentheses(string s) {\n int n = s.size();\...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n int getMinInvalid(string s) {\n stack<char> st;\n for (int i = 0; i < s.size(); i++) {\n if (s[i] == '(') {\n st.push('(');\n } else if (s[i] == ')') {\n if (!st.empty() && st.top() == '(') {\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n\tbool isValid(string &curr){\n\t\tbool ret = true;\n\t\tvector<char> st;\n\t\tfor(int i=0; i<curr.length(); i++){\n\t\t\tif(curr[i] == '(' || curr[i] == '['){\n\t\t\t\tst.push_back(curr[i]);\n\t\t\t}else if(curr[i] == ')'){\n\t\t\t\tif(st.size() == 0 || st.back() != '(')\n\t\t\t...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "// backtrace + pruning\n\nclass Solution {\npublic:\n vector<string> ans = {};\n vector<int> leftNum;\n vector<int> rightNum;\n int minRemoval;\n\n void backtracing(string s, string temp, int i, int left, int right) {\n // cout << temp << endl;\n // cout << left << \" \" << rig...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n set<string> ret;\n set<int> cur_idx_remove;\n\n vector<int> suffix_left; // number of ( in s[i...]\n vector<int> suffix_right; // number of ( in s[i...]\n\n string remove_idx(string s, set<int> idx_remove) {\n string ret;\n for(int i=0;i<s.length();i...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n void solveRec(int ind, string &s, string temp,set<string> &ans){\n if(ind == s.length()){\n int cnt = 0,len = temp.length();\n for(int i = 0;i < len;i++){\n if(temp[i] == '(')\n cnt++;\n else if(tem...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n\n bool isValid(string s){\n stack<char>st;\n for(int i=0;i<s.size();i++){\n if(s[i]=='(')st.push(s[i]);\n else if(s[i]==')'){\n if(!st.empty() && st.top()=='('){\n st.pop();\n }else{\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<string> removeInvalidParentheses(string s) {\n set<string> ans;\n int max = 0;\n helper(0, s, \"\", ans, max, 0);\n vector<string> vec;\n for (auto it : ans) vec.push_back(it);\n ans.clear();\n return vec;\n }\n vo...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<string> removeInvalidParentheses(string s) {\n set<string> ans;\n int max = 0;\n helper(0, s, \"\", ans, max, 0, 0);\n vector<string> vec;\n for (auto it : ans) vec.push_back(it);\n ans.clear();\n return vec;\n }\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<string> removeInvalidParentheses(string s) {\n set<string> ans;\n int max = 0;\n helper(0, s, \"\", ans, max, 0, 0);\n vector<string> vec;\n for (auto it : ans) vec.push_back(it);\n ans.clear();\n return vec;\n }\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\n unordered_set<string>st;\n int mini=0;\n void solve(int ind,string temp,string &s,int d,int x){\n if(d<0)return;\n if(ind==s.size()){\n if(x==0)st.insert(temp);\n return;\n }\n if(s[ind]!='('&&s[ind]!=')'){\n solve(ind...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n vector<string> removeInvalidParentheses(string s) {\n if (s.size() == 1) return {s == \"(\" || s == \")\" ? \"\": s};\n int leftCount = 0, removeRight = 0, removeLeft = 0;\n for (int i = 0; i < s.size(); i++) {\n if (s[i] == '(') {\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n\n void search(string& s, int i, int numLeft, int numRight, int numInvalidLeft, int numInvalidRight, unordered_set<string>& answers, const string& prefix) {\n if (i >= s.size()) {\n if (numInvalidLeft == 0 && numInvalidRight == 0) {\n answers.i...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\n unordered_set<string> setAnsr;\npublic:\n void removeParenthensis(string &s,int ind,int leftP,int rightP,string tmp,int rc){\n if(ind==s.size()){\n if(rc==0 && leftP==0 && rightP==0)\n setAnsr.insert(tmp);\n return ;\n }\n if(rc...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n unordered_set<string> unique_list;\n int global_min = INT_MAX;\n void rec(string& s ,string curr, int index, int left_count, int right_count , int left_rem, int right_rem){\n \n //if(right_count > left_count) return;\n if(index== s.size()){\n ...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n\n void dfs (string &s, int index, int left_removed, int right_removed, int pair, string path, unordered_set<string> &result)\n {\n if (index >= s.size ()){\n if (left_removed == 0 && right_removed == 0 && pair == 0)\n result.insert (path);\...
301
<p>Given a string <code>s</code> that contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid.</p> <p>Return <em>a list of <strong>unique strings</strong> that are valid with the minimum number of removals</em>. You may return the answer in <strong>any order</s...
3
{ "code": "class Solution {\npublic:\n\n void dfs (string &s, int index, int left_removed, int right_removed, int pair, string path, unordered_set<string> &result)\n {\n if (index >= s.size ()){\n if (left_removed == 0 && right_removed == 0 && pair == 0)\n result.insert (path);\...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int heapsize;\n\n void MaxHeapify(vector<int> &p,int i){\n int l=2*i+1; //figlio sinistro\n int r=2*i+2; //figlio destro\n int largest = i;\n\n if(l<heapsize && p[l] > p[largest]){\n largest = l;\n }\n\n if(r<heapsize &&...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\n public:\n int minStoneSum(vector<int>& piles, int k) {\n ios_base::sync_with_stdio(0);\n /* //Method 1\n priority_queue<int> pq(piles.begin(),piles.end());\n while (k-- >...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\n public:\n int minStoneSum(vector<int>& piles, int k) {\n ios_base::sync_with_stdio(0);\n /* //Method 1\n priority_queue<int> pq(piles.begin(),piles.end());\n while (k-- >...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n ios_base::sync_with_stdio(0);\n /* //Method 1\n priority_queue<int> pq(piles.begin(),piles.end());\n while (k-- > 0){\n int t = pq.top();\n pq.pop();\n pq.push(t-t/2);\...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) { \n ios::sync_with_stdio(false);\n cin.tie(0);\n\n make_heap(piles.begin(), piles.end());\n\n while(k--) {\n pop_heap(piles.begin(), piles.end());\n int elem = piles.back() / 2;\n ...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n int freq[10001] = {0};\n int ans = 0;\n for(int pile: piles) {\n ans += pile;\n freq[pile]++;\n }\n for(int i = 10000; i > 1 && k > 0; i--) {\n if(freq[i] > 0) {...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) { \n ios::sync_with_stdio(false);\n cin.tie(0);\n \n make_heap(piles.begin(), piles.end());\n\n while(k--) {\n pop_heap(piles.begin(), piles.end());\n double elem = pile...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) { \n ios::sync_with_stdio(false);\n cin.tie(0);\n \n make_heap(piles.begin(), piles.end());\n\n while(k--) {\n pop_heap(piles.begin(), piles.end());\n double elem = pile...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n make_heap(piles.begin(),piles.end());\n while(k--){\n piles.front() -= piles.front() / 2; \n pop_heap(piles.begin(),piles.end());\n push_heap(piles.begin(),piles.end());\n }\n...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n /* Do k times - choose a pile and remove floor(pile / 2).\n * can do on same pile again.\n * minimum stones remaining after k times.\n */\n // Remove from largest pile at the point in time.\...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n make_heap(piles.begin(), piles.end());\n for (int i = 0; i < k; ++i) {\n pop_heap(piles.begin(), piles.end());\n piles.back() = (piles.back() + 1) / 2;\n push_heap(piles.begin(), pil...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) { \n make_heap(piles.begin(), piles.end());\n\n while(k--) {\n pop_heap(piles.begin(), piles.end());\n double elem = piles.back() / 2.0;\n piles.pop_back();\n piles.pus...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n // int minStoneSum(vector<int>& piles, int k) {\n // priority_queue<int> pq(piles.begin(), piles.end());\n // int sum = accumulate(piles.begin(), piles.end(), 0);\n // while (k--) {\n // int top = pq.top(); pq.pop();\n // sum -= top ...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& v, int k) {\n vector<int> c(10001, 0);\n for (auto &a:v) { c[a]++; }\n\n int s = accumulate(begin(v), end(v), 0);\n\n for (int i = 10000; i > 1; --i) {\n int r = min(k, c[i]);\n\n k -= r;\n ...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n int res = 0;\n // priority_queue<int> q;\n vector<int> count((int)1e4 + 1);\n for (auto pile : piles) {\n // q.push(pile);\n res += pile;\n count[pile] += 1;\n }...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int n;\n vector<int> arr;\n void heapify(int i){\n int index=i;\n int l=2*i,r=2*i+1;\n if(l<n && arr[i]<arr[l]){\n index=l;\n }\n if(r<n && arr[index]<arr[r]){\n index=r;\n }\n if(index!=i){\n ...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n priority_queue<int> heap(piles.begin(), piles.end());\n\n while(k){\n int top = heap.top();\n heap.pop();\n top = top - top/2;\n if(top) heap.push(top);\n k--;\...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n priority_queue<int> maxheap(piles.begin(), piles.end());\n int sum = accumulate(piles.begin(), piles.end(), 0);\n\n while (k--) {\n int num = maxheap.top();\n maxheap.pop();\n sum -= num / 2;\n ...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n priority_queue<int>pq(piles.begin(),piles.end());\n\n while(k--){\n int pile=pq.top();\n pq.pop();\n pq.push((pile+1)/2);\n }\n long long ans=0;\n while(!pq.empt...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n priority_queue<int> heap(piles.begin(), piles.end()); // Initializing max heap\n int totalSum = accumulate(piles.begin(), piles.end(), 0); // Getting entire sum of piles vector\n\n for (int i = 0; i < k; i++)...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n priority_queue<double> heap(piles.begin(),piles.end());\n int curr = 0;\n\n while(curr < k) {\n double maxPile = heap.top();\n heap.pop();\n heap.push(ceil(maxPile/2));\n ...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n std::priority_queue<double> q(piles.begin(), piles.end());\n int sum = accumulate(piles.begin(), piles.end(), 0);\n \n while(k--) {\n int curr = q.top(); q.pop();\n int remove = c...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n priority_queue<double> heap(piles.begin(),piles.end());\n int curr = 0;\n\n while(curr < k) {\n double maxPile = heap.top();\n heap.pop();\n heap.push(ceil(maxPile/2));\n ...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n double minStoneSum(vector<int>& piles, int k)\n {\n priority_queue<double>p(piles.begin(),piles.end());\n \n while(k--)\n {\n double value = ceil(p.top()/2);\n p.pop();\n p.push(value);\n }\n\n double sum=...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n double minStoneSum(vector<int>& piles, int k)\n {\n priority_queue<double>p(piles.begin(),piles.end());\n \n while(k--)\n {\n double value = ceil(p.top()/2);\n p.pop();\n p.push(value);\n }\n\n double sum=...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n\n priority_queue<int> pq(piles.begin(), piles.end());\n while (k-- > 0){ \n pq.push(pq.top() - pq.top() / 2);\n pq.pop();\n }\n int result = 0;\n while (!pq.empty()){\n ...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n if (piles.empty()) return 0;\n unsigned long sum = accumulate(piles.begin(), piles.end(), (unsigned long)0);\n priority_queue<int> heap(piles.begin(), piles.end());\n for (int i = 0; i < k; i++) {\n ...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n if (piles.empty()) return 0;\n unsigned long sum = accumulate(piles.begin(), piles.end(), (unsigned long)0);\n priority_queue<int> heap(piles.begin(), piles.end());\n for (int i = 0; i < k; i++) {\n ...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n int n = piles.size(), res = 0;\n priority_queue<int> pq;\n nth_element(piles.begin(), piles.end() - min(k, n), piles.end());\n for (int i = 0; i < max(0, n - k); i++)\n res += piles[i];\n ...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n int n = piles.size(), res = 0;\n priority_queue<int> pq;\n nth_element(piles.begin(), piles.end() - min(k, n), piles.end());\n for (int i = 0; i < max(0, n - k); i++)\n res += piles[i];\n ...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n int n = piles.size();\n priority_queue<int> pq;\n nth_element(piles.begin(), piles.end() - min(k, n), piles.end());\n int res = 0, m = max(0, n - k);\n for (int i = 0; i < n; i++){\n ...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n priority_queue<int>pq;\n sort(piles.rbegin(),piles.rend());\n int i=0;\n pq.push(piles[0]);\n i++;\n while(k-- && !pq.empty()){\n int num=pq.top();\n pq.pop();\n ...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n \n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(0);\n\n int sum=0;\n priority_queue<int>pq;\n\n for(int i=0;i<piles.size();i++) {\n sum+=piles[i];\n ...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "static const int _ = [] {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n priority_queue<int> pq;\n\n for (int i = 0; i < piles.size(); i++) {\n pq...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "class Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n\n ios_base::sync_with_stdio(0);\n priority_queue<int>pq;\n for(int i = 0 ; i<piles.size() ; i++){\n pq.push(piles[i]);\n }\n\n while(k--){\n int topEle = pq.top();\n ...
2,094
<p>You are given a <strong>0-indexed</strong> integer array <code>piles</code>, where <code>piles[i]</code> represents the number of stones in the <code>i<sup>th</sup></code> pile, and an integer <code>k</code>. You should apply the following operation <strong>exactly</strong> <code>k</code> times:</p> <ul> <li>Choos...
0
{ "code": "static const int _ = [] {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution {\npublic:\n int minStoneSum(vector<int>& piles, int k) {\n priority_queue<int> pq;\n\n for (int i = 0; i < piles.size(); i++) {\n pq...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "class Solution {\n int n;\npublic:\n int solve(vector<int> &nums,int l,vector<int> &multipliers,int i,vector<vector<int>> &dp){\n if(i == multipliers.size()) return 0;\n \n if(dp[l][i] != INT_MIN) return dp[l][i];\n \n int r=n-1-(i-l);\n \n int include...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> dp;\n\n int solve(int i, int j, vector<int>& nums, vector<int>& mlt) {\n int m = mlt.size();\n int n = nums.size();\n if (i + j == m) return 0;\n if (dp[i][j] != INT_MIN) return dp[i][j];\n int left = mlt[i + j] * nums...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "class Solution {\npublic:\n int func(int i, int j, int m, vector<int> &arr, vector<int> &multipliers, vector<vector<int>> &dp) {\n int k = i+arr.size()-j-1;\n if (k == m || i > j) return 0;\n if (dp[i][j] != -1) return dp[i][j];\n \n int ans = max(func(i+1, j, m, arr, ...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "class Solution {\npublic:\n\n\n long long solve(vector < int > & nums , vector < int > & multi , int left , \n int n , int index , vector < vector < long long >> & dp){\n\n if(index == multi.size()) {\n return 0; \n }\n\n if(dp[left][index] != 1e13) {\n retu...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "class Solution {\npublic:\n\n\n long long solve(vector < int > & nums , vector < int > & multi , int left , \n int n , int index , vector < vector < long long >> & dp){\n\n if(index == multi.size()) {\n return 0; \n }\n\n if(dp[left][index] != 1e13) {\n retu...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "class Solution {\n unordered_map<int, unordered_map<int, int>> memo;\n int TopDown(vector<int>& nums, vector<int>& multipliers, int start, int i) {\n int end = nums.size() - 1 - (i - start);\n if (i == multipliers.size())\n return 0;\n if (memo.find(i) == memo.end() |...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "class Solution {\n unordered_map<int, unordered_map<int, int>> memo;\n int TopDown(vector<int>& nums, vector<int>& multipliers, int start, int i) {\n int end = nums.size() - 1 - (i - start);\n if (i == multipliers.size())\n return 0;\n if (memo.find(i) == memo.end() |...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "class Solution {\n unordered_map<int, unordered_map<int, int>> dp;\npublic:\n \n int maxRecur(vector<int>& nums, vector<int>& multipliers, int i, int left) {\n if (i == multipliers.size()) return 0;\n if (dp.count(i) && dp[i].count(left)) return dp[i][left];\n \n int val...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "class Solution {\n unordered_map<int, unordered_map<int, int>> memo;\n int TopDown(vector<int>& nums, vector<int>& multipliers, int start, int i) {\n int end = nums.size() - 1 - (i - start);\n if (i == multipliers.size())\n return 0;\n if (memo.find(i) == memo.end() |...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "class Solution {\npublic:\n int n,m;\n unordered_map<int,unordered_map<int,int>> cache;\n \n int maximumScore(vector<int>& nums, vector<int>& multipliers,int start,int end,int j){\n if(j==m or start>end) return 0;\n if(cache[start].find(end)!=cache[start].end()) return cache[start...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "//Very good question \n//Just do hasing\n//Only values till 600 is possible\n//This is because mp len is 300\n//Odds for end index\n//evens for beg index\n\n#define ll long long\n#define pb push_back\nclass Solution {\npublic:\n ll f(ll beg,ll end,vector<vector<ll>>& dp,vector<int>& arr,vector<int>& mp,...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "// 2D dp\n// Nums vector & multipliers vector (0-indexed)\n\n// Begin with score of 0\n\n// On the i'th iteration, choose one integer from either the start or the end of the array nums\n// Add multipliers[i] * x to your score\n\n// Remove x from nums\n// Do we really need to remove X from nums? How about j...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "class Solution {\n\nprivate:\n\tstd::vector<int> nums;\n\tstd::vector<int> multipliers;\n\t\n\t// Hash map definition\n\tstruct Key{\n\t\tint left;\n\t\tint multIndex;\n\t\t\n\t\t//constructor \n\t\tKey(int k1,int k2):left(k1),multIndex(k2){}\n\t\t\n\t\tbool operator==(const Key& other) const{\n\t\t\tretur...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "int dp[300][300][300];\nclass Solution {\npublic:\n int f(int start,int end,int moves,int k,vector<int>&nums, vector<int>& mul)\n {\n if(moves==k)return 0;\n int ans=-1e9;\n if(dp[start][end][moves]!=-1)return dp[start][end][moves];\n ans=max(ans,nums[start]*mul[moves] + f...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, vector<int>& multipliers) {\n int m = multipliers.size();\n int n = nums.size();\n int** dp = new int*[m+1];\n for (int i = 0; i < m+1; i++) {\n dp[i] = new int[n+1];\n std::fill(dp[i], dp[i...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "class Solution {\npublic:\n int maximumScore(vector<int>& nums, vector<int>& multipliers) {\n int m = multipliers.size();\n int n = nums.size();\n int** dp = new int*[m+1];\n for (int i = 0; i < m+1; i++) {\n dp[i] = new int[n+1];\n std::fill(dp[i], dp[i...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "class Solution {\nprivate:\n int m, n;\n int** memo;\n vector<int> nums;\n vector<int> multipliers;\n int dp(int i, int left) {\n if (i == m) {\n return 0;\n }\n \n int mult = multipliers[i];\n int right = n - 1 - (i - left);\n if (memo[i]...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "int dp[(int)1e5][301];\n\nclass Solution {\n\nprivate:\n int solveMemo(int i,int k,vector<int> &nums,vector<int> &arr,int n,int m){\n if(k == m) return 0;\n\n if(dp[i][k]!=-1) return dp[i][k];\n\n int j = (n-(k-i))-1;\n\n int op1 = nums[i]*arr[k] + solveMemo(i+1,k+1,nums,arr,...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "static constexpr int maxN = 1e5 + 5, maxM = 3e2 + 5;\nint dp[maxN][maxM];\nclass Solution {\npublic:\n int maximumScore(vector<int>& nums, vector<int>& mul) {\n int n = nums.size(), m = mul.size();\n memset(dp, -1, sizeof(dp));\n auto dfs = [&](auto&& dfs, int i, int j) {\n ...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "class Solution {\n vector<int> nums;\n vector<int> multipliers;\n\n std::map<std::vector<int>, int> dp;\n \n int solve(int first_num, int last_num, int mi) {\n std::vector<int> index {first_num, last_num, mi};\n auto it = dp.find(index);\n if(it != std::end(dp)) return i...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "class Solution {\nprivate:\n int M; \n int N;\n vector<int> nums;\n vector<int> mults;\n map<vector<int>, int> memo;\npublic:\n int solve(int m, int i, int j) {\n // base case \n if (m == M) return 0;\n if (i > j) return 0;\n if (i == N || j == -1) return 0;\n\...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "#include <vector>\n#include <unordered_map>\n#include <functional> // for std::hash\n\nclass Solution {\npublic:\n // Custom hash function for vector<int>\n struct VectorHash {\n std::size_t operator()(const std::vector<int>& v) const {\n std::size_t seed = v.size();\n fo...
1,896
<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n &gt;= m</code>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</cod...
2
{ "code": "class Solution {\npublic:\n int func(int ind,int i,int j,vector<int>&a,vector<int> &mul,map<vector<int>,int>&mp){\n int m=mul.size();\n if(ind>=m) return 0;\n if(mp.find({ind,i,j})!=mp.end()) return mp[{ind,i,j}];\n int ans=max(mul[ind]*a[j]+func(ind+1,i,j-1,a,mul,mp),mul[ind...