id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n vector<string> FilterLetters(string digits) {\n unordered_map<char, string> mp = {\n {'2', \"abc\"}, {'3', \"def\"}, {'4', \"ghi\"}, {'5', \"jkl\"},\n {'6', \"mno\"}, {'7', \"pqrs\"}, {'8', \"tuv\"}, {'9', \"wxyz\"}};\n\n vector<string> re...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n vector<string> letterCombinations(string digits) {\n if(digits.empty()){ return {};}\n vector<string> res = phonePad(\"\", digits);\n return res;\n \n \n }\n public:\n vector<string>phonePad(string p, string up){\n vector<...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n map<int,string> buttons;\n Solution(){\n buttons[2]=\"abc\";\n buttons[3]=\"def\";\n buttons[4]=\"ghi\";\n buttons[5]=\"jkl\";\n buttons[6]=\"mno\";\n buttons[7]=\"pqrs\";\n buttons[8]=\"tuv\";\n buttons[9]=\"wxyz\";\...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n \n void solve(int ind,vector<string>st,vector<string>&ans,string res){\n \n if(ind == st.size()){\n if(res!=\"\")\n ans.push_back(res);\n return;\n }\n \n for(int i = 0;i<st[ind].size();i++){\n ...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n map<char,string> mp = {{'2',\"abc\"},{'3',\"def\"}, {'4',\"ghi\"}, {'5',\"jkl\"}, {'6',\"mno\"}, {'7',\"pqrs\"}, {'8',\"tuv\"}, {'9',\"wxyz\"}};\n vector<string> ans;\n void solve (string pro, string digit){\n if(digit.size()==0) {\n ans.push_back(pro);\...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n void bruteforce(int idx, string digits, string currCombination, vector<string>& allCombinations) {\n if (idx == digits.length()) {\n // список превращаем в строку\n allCombinations.push_back(currCombination);\n return;\n }\n ...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n void solve(string digits,string a,vector<string> s,vector<string> &ans,int i)\n {\n if(i==digits.length())\n {\n ans.push_back(a);\n return;\n }\n for(int j=0;j<s[digits[i]-'2'].length();j++)\n {\n solve(digits,a+s[digits[i]-'2'][j],s,ans,...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n //std::string phone_map[] = {\"abc\", \"def\", \"ghi\", \"jkl\", \"mno\", \"pqrs\", \"tuv\", \"wxyz\"};\n\n void backtrack(vector<string>& ans, string digits, string comb, int idx) {\n std::string phone_map[] = {\"abc\", \"def\", \"ghi\", \"jkl\", \"mno\", \"pqrs\",...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n vector<string> mapping(char c){\n if(c=='2') return {\"a\", \"b\", \"c\"};\n else if(c=='3') return {\"d\", \"e\", \"f\"};\n else if(c=='4') return {\"g\", \"h\", \"i\"};\n else if(c=='5') return {\"j\", \"k\", \"l\"};\n else if(c=='6') retu...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n\n void recursion(string digits, vector<string> mappings, int index, string & temp, vector<string> & ans) {\n\n if(index == digits.size()) {\n ans.push_back(temp);\n return;\n }\n\n string letters = mappings[digits[index] - '2'];\n\n ...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n vector<string> letterCombinations(string digits) {\n std::vector<std::string> result;\n if(digits.size() > 0)\n {\n std::queue<std::string> strQueue;\n int firstDigit = digits[0] - '0';\n pushNumber(strQueue, firstDigit);\...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n vector<string> letterCombinations(string digits) {\n vector <string>ans;\n string output = \"\";\n int index = 0;\n vector<string> mapping = {\"\",\"\",\"abc\",\"def\",\"ghi\",\"jkl\",\"mno\",\"pqrs\",\"tuv\",\"wxyz\"};\n if(digits.size() ==...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n void helper(int k, int n, string digits, vector<string>v, vector<string> &ans, string &temp){\n if(k==n){\n ans.push_back(temp);\n return;\n }\n int key=digits[k]-'0';\n int l=v[key].length();\n for(int i=0;i<l;i++){\n ...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n vector<string> letterCombinations(string digits) {\n vector<string> ans;\n string output;\n if(digits.length()==0){\n return ans;\n }\n int i=0;\n vector<string> mapping={\"\",\"\",\"abc\",\"def\",\"ghi\",\"jkl\",\"mno\",\"...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\n void combination(vector<string> & result,string word,string digits,vector<string> values,int itr)\n {\n if(word.size()==digits.size())\n result.push_back(word);\n else\n {\n for(int i=0;i<values[digits[itr]-48].size();i++)\n combin...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n void solve(vector<string>s,string temp,string digits,int index,vector<string>&ans){\n if(index==digits.size() && temp!=\"\"){\n ans.push_back(temp);\n return;\n }\n for(int i=0;i<s.size();i++){\n if(digits[index]-'0'==i){\n for(int j=0;...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n void fun(int size,int idx,string& digits,vector<string>& ans,string& substr,unordered_map<int,vector<char>> mpp){\n if(idx >= size){\n ans.push_back(substr);\n return;\n }\n int digit = digits[idx] - '0';\n int sizeoftheloop =...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n void helper(vector<string> keypad,string ans,int index,vector<string>& result,string digits)\n {\n if(ans.size()==digits.size())\n {\n result.push_back(ans);\n return;\n }\n int digit=digits[index]-'0';\n string lett...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n void solve(vector<string>&ans,string output,int i,vector<string>mapping, string digits){\n \n if(i==digits.size()){\n ans.push_back(output);\n return;\n }\n int num = digits[i]-'0';\n\n string digit = mapping[num];\n \n for(auto it:digit){\n ...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n void findcombi(string digits,string&ans,vector<string>&v,unordered_map<int,string>mp,int i){\n if(ans.size()==digits.size()){\n v.push_back(ans);\n return;\n }\n \n int digit=digits[i]-'0';\n for(auto letter:mp[digit]){\n ...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n void f(string& digits, vector<string>& ans, string temp, int idx, unordered_map<int,vector<char> > mp){\n // Base case.\n if(idx == digits.size()){\n if(temp.length() >= 1) ans.push_back(temp);\n return;\n }\n\n int num = digi...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\n private:\n void solve(vector<string>record,string digits,int i,string output,vector<string>& ans){\n if(i>=digits.size()){\n if(output. length()!=0)\n ans.push_back (output);\n return;\n }\n int num=digits[i]-'0';\n string...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\npublic:\n void printVector(vector<string> res)\n {\n for(string str :res)\n {\n std::cout<<str<<std::endl;\n }\n std::cout<<\"----------------------------------------------\"<<std::endl;\n }\n vector<string> dfsPattern(std::unordered_map<...
17
<p>Given a string containing digits from <code>2-9</code> inclusive, return all possible letter combinations that the number could represent. Return the answer in <strong>any order</strong>.</p> <p>A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any lette...
3
{ "code": "class Solution {\n void solve(string digits, string output, int i, vector<string>& answer, unordered_map<int, string> mapping){\n\n if(i >= digits.size())\n {\n answer.push_back(output);\n return;\n }\n\n string value = mapping[int(digits[i] - 48)];\n\n ...
19
<p>Given the <code>head</code> of a linked list, remove the <code>n<sup>th</sup></code> node from the end of the list and return its head.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg" style="width: 542px; height: 22...
0
{ "code": "static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\n\nint init = [] {\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n for (string str, n_str; getline(cin, str) && getline(cin, n_str); cout << '\\n') {\n ...
19
<p>Given the <code>head</code> of a linked list, remove the <code>n<sup>th</sup></code> node from the end of the list and return its head.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg" style="width: 542px; height: 22...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nstatic const int __ = [](){...
19
<p>Given the <code>head</code> of a linked list, remove the <code>n<sup>th</sup></code> node from the end of the list and return its head.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg" style="width: 542px; height: 22...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nstatic const int __ = [](){...
19
<p>Given the <code>head</code> of a linked list, remove the <code>n<sup>th</sup></code> node from the end of the list and return its head.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg" style="width: 542px; height: 22...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nstatic const int __ = [](){...
19
<p>Given the <code>head</code> of a linked list, remove the <code>n<sup>th</sup></code> node from the end of the list and return its head.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg" style="width: 542px; height: 22...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nstatic const int __ = [](){...
19
<p>Given the <code>head</code> of a linked list, remove the <code>n<sup>th</sup></code> node from the end of the list and return its head.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg" style="width: 542px; height: 22...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
19
<p>Given the <code>head</code> of a linked list, remove the <code>n<sup>th</sup></code> node from the end of the list and return its head.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg" style="width: 542px; height: 22...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
19
<p>Given the <code>head</code> of a linked list, remove the <code>n<sup>th</sup></code> node from the end of the list and return its head.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg" style="width: 542px; height: 22...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
19
<p>Given the <code>head</code> of a linked list, remove the <code>n<sup>th</sup></code> node from the end of the list and return its head.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg" style="width: 542px; height: 22...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
19
<p>Given the <code>head</code> of a linked list, remove the <code>n<sup>th</sup></code> node from the end of the list and return its head.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg" style="width: 542px; height: 22...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
19
<p>Given the <code>head</code> of a linked list, remove the <code>n<sup>th</sup></code> node from the end of the list and return its head.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg" style="width: 542px; height: 22...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
19
<p>Given the <code>head</code> of a linked list, remove the <code>n<sup>th</sup></code> node from the end of the list and return its head.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg" style="width: 542px; height: 22...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
19
<p>Given the <code>head</code> of a linked list, remove the <code>n<sup>th</sup></code> node from the end of the list and return its head.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg" style="width: 542px; height: 22...
0
{ "code": "class Solution {\npublic:\n ListNode* removeNthFromEnd(ListNode* head, int n) {\n ListNode* dummy = new ListNode(0);\n dummy->next = head;\n ListNode* first = dummy;\n ListNode* second = dummy;\n\n for (int i = 0; i <= n; ++i) {\n first = first->next;\n ...
19
<p>Given the <code>head</code> of a linked list, remove the <code>n<sup>th</sup></code> node from the end of the list and return its head.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg" style="width: 542px; height: 22...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
0
{ "code": "#include <string>\n\nclass Solution {\npublic:\n bool isValid(std::string s) {\n std::string stack;\n\n auto match_char = [&](char expected){\n if (empty(stack) || stack.back() != expected) return false;\n stack.pop_back();\n return true;\n };\n\n ...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
0
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n int n = s.size();\n\n // OPTIMAL\n // stack<char> st;\n\n // for (int i = 0; i < n; i++) {\n // if (s[i] == '(' || s[i] == '{' || s[i] == '[') {\n // st.push(s[i]);\n // } else if (st....
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
0
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n string stk;\n for (char c : s) {\n if (c == '(' || c == '{' || c == '[')\n stk.push_back(c);\n else if (stk.empty() || !match(stk.back(), c))\n return false;\n else\n ...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
0
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n stack<char> sta;\n for (char c : s){\n if (c == '(' || c == '[' || c == '{') sta.push(c);\n else{\n if (sta.empty()) return false;\n char t = sta.top();\n if ((c == ')'...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
0
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n vector<char> tmp;\n int len = s.size();\n\n for(char ch:s) {\n if (ch=='(' || ch=='[' || ch == '{') {\n tmp.push_back(ch);\n }\n else {\n if (tmp.empty()) return fal...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
0
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n stack<char> stackA;\n int n=s.size();\n for(int i=0;i<n;i++){\n char ch=s[i];\n // if openeing brackets are there\n if(ch=='(' || ch=='{' || ch=='['){\n stackA.push(ch);\n }\n el...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
0
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n stack<char>st;\n \n string a=\"()\";\n string b=\"[]\";\n string d=\"{}\";\n for(char c : s)\n {\n if(c=='(' || c=='[' || c=='{')\n {\n st.push(c);\n }\n...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
0
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n stack<char>st;\n for(char c:s){\n if(c== '('|| c== '{'|| c== '['){\n st.push(c);\n }\n else{\n if(st.empty()||(c==')' && st.top() !='(')||(c=='}' && st.top() !='{')||(c==']' && st.top() !='[')){\n ...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
0
{ "code": "class Solution {\npublic:\n\n char GetPairBracket(char bracket) {\n if (bracket == '(') {\n return ')';\n }\n if (bracket == '{') {\n return '}';\n }\n return ']';\n }\n\n bool isValid(string brackets) {\n std::stack<char> stack_brack...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
0
{ "code": "class Solution {\npublic:\n char OpenPare(char par){\n char open_pare;\n if(par == ']'){\n open_pare = '[';\n }\n if(par == '}'){\n open_pare = '{';\n }\n if(par == ')'){\n open_pare = '(';\n }\n return open_pare;\n...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
1
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n stack<char> st ; \n for (int i = 0 ; i< s.length() ; i++)\n {\n char ch = s[i];\n\n\n if (ch == '(' || ch == '{' || ch == '[')\n {\n st.push(ch) ; \n }\n\n e...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
1
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n stack<char> st;\n for(int i=0; i<s.length(); i++) {\n char ch = s[i];\n\n // If it's an opening bracket, push onto the stack\n if(ch == '(' || ch == '[' || ch == '{') {\n st.push(ch);\n ...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
2
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n stack<char> st;\n int n = s.length();\n if(n%2 != 0) return false;\n for(int i=0;i<n;i++){\n if(s[i] == '(' || s[i]== '[' || s[i]== '{'){\n st.push(s[i]);\n }\n else if(s[i]...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
2
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n stack<char> st; \n for (char c : s) { \n if (c == '(' || c == '{' || c == '[') {\n st.push(c); \n } else { \n if (st.empty() || \n (c == ')' && st.top() != '(') || ...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
3
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n int n = s.size();\n stack<int> st;\n for(int i =0;i<n;i++){\n if(s[i] == '('|| s[i] == '{'|| s[i] == '['){\n st.push(s[i]);\n } else {\n if(st.empty()) return false;\n ...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
3
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n stack<char> st;\n unordered_map<char, char> charMap = {\n {')', '('},\n {'}', '{'},\n {']', '['}\n };\n\n for(char c : s){\n if(c == '(' || c == '{' || c == '[') {\n ...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
3
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n ios_base::sync_with_stdio(false);\n cin.tie(0);\n\n stack<char> open;\n unordered_map<char, char> parens = {\n {')', '('},\n {']', '['},\n {'}', '{'},\n };\n for (const auto&...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
3
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n stack<char> stack1;\n\n for(int i = 0;i<s.size();i++){\n if(s[i]=='('){\n stack1.push(')');\n }\n else if(s[i]=='{'){\n stack1.push('}');\n } \n else ...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
3
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n stack<char> st;\n unordered_map<char, char> m;\n\n m['(']=')';\n m['{']='}';\n m['[']=']';\n\n char prev='a';\n\n if(s.length()==1)return false;\n for(int i=0; i<s.length(); i++){\n ...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
3
{ "code": "class Solution {\nprivate:\n bool isOpen(char c) {\n return c == '(' or c == '{' or c == '[';\n }\n bool isClose(char c) {\n return c == ')' or c == '}' or c == ']';\n }\n bool ArePair(char open, char close) {\n if (open == '(') {\n return close == ')';\n ...
20
<p>Given a string <code>s</code> containing just the characters <code>&#39;(&#39;</code>, <code>&#39;)&#39;</code>, <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;[&#39;</code> and <code>&#39;]&#39;</code>, determine if the input string is valid.</p> <p>An input string is valid if:</p> <ol> <li>Open ...
3
{ "code": "class Solution {\npublic:\n bool isValid(string s) {\n std::stack<char> q;\n for(char c : s) {\n if(c=='(') { q.push(')'); continue; }\n if(c=='{') { q.push('}'); continue; }\n if(c=='[') { q.push(']'); continue; } \n if(q.empty() || c != q.top()...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
0
{ "code": "\n#include <iostream>\nclass Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n int s = boxTypes.size();\n int temp;\n int unitsum=0;\n for(int i=0;i<s;i++){\n temp =boxTypes[i][0];\n boxTypes[i][0]=boxTypes[...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
0
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n sort(boxTypes.begin(), boxTypes.end(),\n [](const vector<int>& a, const vector<int>& b) {\n return a[1] > b[1];\n });\n int totalUnits = 0;\n for (c...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
0
{ "code": "bool cmp(vector<int>& b1, vector<int>& b2) { return b1[1] > b2[1]; }\n\nclass Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n sort(boxTypes.begin(), boxTypes.end(), cmp);\n int max_unit = 0;\n for (int i = 0; i < boxTypes.size(); i++) {\n ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
0
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n int sum=0,max=0,index=0;\n\n while(truckSize>0){\n max=0;index=0;\n for(int i=0;i<boxTypes.size();i++){\n if(boxTypes[i][1]>max){\n max=box...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
0
{ "code": "bool cmp(vector<int>& a,vector<int>& b){\n return a[1]>b[1];\n}\nclass Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n sort(boxTypes.begin(),boxTypes.end(),cmp);\n int profit=0;\n for(int i=0;i<boxTypes.size();i++){\n if(boxType...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
0
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n int sum=0,max=0,index=0;\n\n while(truckSize>0){\n max=0;index=0;\n for(int i=0;i<boxTypes.size();i++){\n if(boxTypes[i][1]>max){\n max=box...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
0
{ "code": "class Solution {\npublic:\n\n static bool sortfn(const vector<int>& v1,const vector<int>& v2)\n {\n return (v1[1]>v2[1]);\n }\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n if(boxTypes.size()==0)\n return 0;\n int ans = 0;\n sort(boxTypes...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
0
{ "code": "bool cmp(vector<int>& a,vector<int>& b){\n return a[1]>b[1];\n}\nclass Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n sort(boxTypes.begin(),boxTypes.end(),cmp);\n int profit=0;\n for(int i=0;i<boxTypes.size();i++){\n if(boxType...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
1
{ "code": "struct BoxTypesComparer {\n bool operator()(const vector<int> &lh, const vector<int> &rh) const {\n return lh[1] < rh[1];\n }\n};\nclass Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n int ret = 0;\n sort(boxTypes.begin(), boxTypes.end(...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& nums, int count) {\n vector <pair <int, int> > v(nums.size());\n for(int i=0; i<nums.size(); ++i) {\n pair <int, int> p;\n p.first = nums[i][1];\n p.second = nums[i][0];\n v[i] = p...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& nums, int count) {\n vector <pair <int, int> > v(nums.size());\n for(int i=0; i<nums.size(); ++i) {\n pair <int, int> p;\n p.first = nums[i][1];\n p.second = nums[i][0];\n v[i] = p...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& b, int t) {\n vector<int> a;\n int ans = 0;\n\n for (int i = 0; i < b.size(); i++) {\n a.push_back(b[i][1]);\n }\n\n sort(a.begin(), a.end());\n\n for (int i = a.size() - 1; i >= 0 && t...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& b, int t) {\n vector<int> a;\n int ans = 0;\n\n for (int i = 0; i < b.size(); i++) {\n a.push_back(b[i][1]);\n }\n\n sort(a.begin(), a.end());\n\n for (int i = a.size() - 1; i >= 0 && t...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n //THE COMMENTED APPORACH IS CORRECT BUT IS TOO HUGE TO USE IN THIS \n //QUESTION\n\n // int solve(vector<vector<int>>& arr, int target, int i, vector<vector<int>> &dp){\n // //base case\n // if(target==0){\n // return 0;\n // }\n // ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n\nstatic bool cmp(pair<int,int> a, pair<int,int> b)\n{\n return a.second>b.second;\n}\n\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n vector<pair<int,int> > v;\n\n for(int i=0;i<boxTypes.size();i++)\n {\n pair<int,int> ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n static bool fn(vector<int>& a, vector<int>& b) {\n if(a[1]!=b[1]) return a[1]>b[1];\n return a[0]>b[0]; \n }\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n sort(boxTypes.begin(),boxTypes.end(),fn);\n for(auto x:boxTypes)...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n \n int res = 0, n = boxTypes.size();\n\n sort(boxTypes.begin(), boxTypes.end(), \n [](auto & a, auto & b) \n { \n return a[1] > b[1]; \n });\n\n for(...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n sort(boxTypes.begin(),boxTypes.end(),\n [](vector<int> &v1,vector<int> &v2){\n return v1[1] > v2[1];\n });\n int maxunits = 0;\n for(auto i: boxTypes){\n ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) \n {\n int n = boxTypes.size();\n int count = 0; \n map<int,int> mp;\n for(int i = 0; i < n; ++i)\n {\n mp[boxTypes[i][1]] += boxTypes[i][0];\n }\n\n ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "#include <vector>\n#include <map>\nusing namespace std;\n\nclass Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n int a = 0;\n map<int, int, greater<int>> box; \n for(int i = 0; i < boxTypes.size(); i++) {\n box[boxTypes[i][1]] += boxTy...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n int ans = 0;\n vector<int> units(1001, 0);\n for (auto box : boxTypes) {\n units[box[1]] += box[0];\n }\n for (int i = 1000; i >= 1 && truckSize; i--) {\n ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n priority_queue<pair<int, int>> valpq;\n \n for (int i = 0; i < boxTypes.size(); ++i) {\n vector<int> curtype = boxTypes[i];\n \n int numboxes = curtype[0];...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n priority_queue<pair<int, int>> pq;\n int count=0;\n for(vector<int> x: boxTypes){\n pq.push({x[1], x[0]});\n }\n\n int units=0;\n while(!pq.empty() && count...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n vector<pair<int,int>> B;\n for (auto bt : boxTypes) {\n B.push_back(make_pair(bt[1], bt[0]));\n }\n sort(B.begin(), B.end());\n reverse(B.begin(), B.end());\n ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n\n struct Node {\n int left;\n int right;\n\n bool operator < (const Node& t) const {\n return right < t.right;\n }\n };\n\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n vector<Node> arr;\n for (c...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int n) {\n priority_queue<pair<int,int>> pq;\n for(auto it:boxTypes){\n pq.push({it[1],it[0]});\n }\n int cnt = 0;\n int ans = 0;\n while(!pq.empty() && cnt < n){\n ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n sort(boxTypes.begin(),boxTypes.end(),[](const vector<int>& a, const\n vector<int>& b) {\n return a[1] > b[1];\n });\n for(auto it:boxTypes)cout<<it[0]<<\" \"<<it[1]<<en...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n sort(boxTypes.begin(),boxTypes.end(),[](const vector<int>& a, const\n vector<int>& b) {\n return a[1] > b[1];\n });\n for(auto it:boxTypes)cout<<it[0]<<\" \"<<it[1]<<en...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "\nbool cmp(vector<int>&a,vector<int>&b){\n return a[1]>b[1];\n}\nclass Solution {\npublic:\n int maximumUnits(vector<vector<int>>& box, int size) {\n sort(box.begin(),box.end(),cmp);\n for(auto it:box){\n for(int j:it){\n cout<<j<<\" \"; \n }\n ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n multimap<int, int> m;\n for (int i = 0; i < boxTypes.size(); i++) {\n m.insert({boxTypes[i][1], boxTypes[i][0]});\n }\n int res = 0;\n for (auto it = m.rbegin(); i...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n int ans = 0;\n\n multimap<int, int> m;\n\n for(int i = 0; i < boxTypes.size(); i++){\n m.insert({boxTypes[i][1], boxTypes[i][0]});\n }\n\n for(auto it = m.rbegin()...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n std::map<int, int, std::greater<int>> M;\n for(auto boxType: boxTypes)\n M[boxType[1]] += boxType[0];\n\n int ans = 0;\n for(auto x: M) {\n ans += min(truckSiz...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& arr, int s) {\n vector<pair<double,int>> temp;\n int i = 0 ;\n for(auto it : arr){\n temp.push_back({(double)(it[1]*it[0])/(double)(it[0]),i});\n i++;\n }\n sort(temp.begin() , temp...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n for (int i = 0; i < boxTypes.size(); i++) {\n int temp = boxTypes[i][0];\n boxTypes[i][0] = boxTypes[i][1];\n boxTypes[i][1] = temp;\n }\n\n sort(boxTypes....
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int w) {\n vector<vector<int>>unit;\n for (int i = 0; i < boxTypes.size(); i++) {\n unit.push_back({boxTypes[i][1],boxTypes[i][0]});\n }\n sort(unit.begin(), unit.end(), greater<vector<int>...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\n\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n\n int n = boxTypes.size();\n int tar = 0, ans = 0;\n\n for(int i=0;i<n;i++){\n swap(boxTypes[i][0],boxTypes[...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
2
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n for (int i = 0; i < boxTypes.size(); i++) {\n int temp = boxTypes[i][0];\n boxTypes[i][0] = boxTypes[i][1];\n boxTypes[i][1] = temp;\n }\n\n sort(boxTypes....
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n int ans = 0;\n vector<vector<int>> list(boxTypes.size());\n for(int i = 0; i < boxTypes.size(); i++)\n {\n list[i].push_back(boxTypes[i][1]);\n list[i].push_ba...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n int ans = 0;\n vector<vector<int>> list(boxTypes.size());\n for(int i = 0; i < boxTypes.size(); i++)\n {\n list[i].push_back(boxTypes[i][1]);\n list[i].push_ba...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& bT, int num) {\n int n=bT.size();\n vector<pair<int,int>>v;\n for(int a=0;a<n;a++){\n v.push_back({bT[a][1],bT[a][0]});\n }\n sort(v.rbegin(),v.rend());\n for(int a=0;a<n;a++){\n ...
1,829
<p>You are assigned to put some amount of boxes onto <strong>one truck</strong>. You are given a 2D array <code>boxTypes</code>, where <code>boxTypes[i] = [numberOfBoxes<sub>i</sub>, numberOfUnitsPerBox<sub>i</sub>]</code>:</p> <ul> <li><code>numberOfBoxes<sub>i</sub></code> is the number of boxes of type <code>i</co...
3
{ "code": "class Solution {\npublic:\n int maximumUnits(vector<vector<int>>& boxTypes, int truckSize) {\n int d=truckSize;\n vector<pair<int,int>>s;\n for(int i=0;i<boxTypes.size();i++)\n {\n s.push_back({boxTypes[i][1],boxTypes[i][0]});\n\n }\n\n sort(s.rbe...