id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,381 | <p>Given a list of <code>words</code>, list of single <code>letters</code> (might be repeating) and <code>score</code> of every character.</p>
<p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two or ... | 3 | {
"code": "class Solution {\npublic:\n int solve(int i, vector<string> curr, int n, vector<string>& words, vector<char>& letters, vector<int>& score, vector<int> &freq){\n if(i==n){\n vector<int> temp = freq;\n int ans = 0;\n for(auto word: curr){\n int sc = 0... |
1,381 | <p>Given a list of <code>words</code>, list of single <code>letters</code> (might be repeating) and <code>score</code> of every character.</p>
<p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two or ... | 3 | {
"code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n int n = words.size();\n unordered_map<char, int> mp;\n int maxm = 0;\n \n for(auto v : letters) mp[v]++;\n \n for(int bit = 0; bit < (1 << ... |
1,381 | <p>Given a list of <code>words</code>, list of single <code>letters</code> (might be repeating) and <code>score</code> of every character.</p>
<p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two or ... | 3 | {
"code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& words, vector<char>& letters, vector<int>& score) {\n int n = words.size();\n int mx=0;\n map<char,int> let;\n for(auto e:letters) let[e]++;\n for(int i=0;i<(1<<n);i++){\n vector<string> tmp;\n ... |
1,381 | <p>Given a list of <code>words</code>, list of single <code>letters</code> (might be repeating) and <code>score</code> of every character.</p>
<p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two or ... | 3 | {
"code": "class Solution {\npublic:\n int maxScoreWords(vector<string>& a, vector<char>& letters, vector<int>& score) {\n \n int ans=0;\n int n=a.size();\n int mx= pow(2,n);\n \n for(int i=0;i<mx;i++)\n {\n vector<string> take;\n \n for(int j=0;j... |
1,381 | <p>Given a list of <code>words</code>, list of single <code>letters</code> (might be repeating) and <code>score</code> of every character.</p>
<p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two or ... | 3 | {
"code": "class Solution {\npublic:\n set<vector<string> > solve(vector<string>& v)\n {\n // To store the resulting subsets\n set<vector<string> > res;\n vector<string> subset;\n vector<vector<string> > result;\n\n // Insert it into the resultant vector\n res.insert(su... |
1,381 | <p>Given a list of <code>words</code>, list of single <code>letters</code> (might be repeating) and <code>score</code> of every character.</p>
<p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two or ... | 3 | {
"code": "class Solution {\n\nprivate: \n int get_score(vector<string> &comb, vector<string> &w, vector<char> &l, vector<int> &sc, map<char,int> mp)\n {\n int scf = 0;\n for(auto word: comb)\n {\n cout<<word<<endl;\n int w1 = 0;\n for (auto c:word)\n ... |
1,381 | <p>Given a list of <code>words</code>, list of single <code>letters</code> (might be repeating) and <code>score</code> of every character.</p>
<p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two or ... | 3 | {
"code": "typedef vector<int> vi;\n\nbool is_usable(string& word, array<int, 26>& letters_cnt) {\n for (int i = 0; i < 26; i++) {\n int cnt = 0;\n for (auto elem : word) if (elem == i + 'a') cnt++;\n if (letters_cnt[i] < cnt) return false;\n }\n return true;\n}\n\nint score_by_word(stri... |
1,381 | <p>Given a list of <code>words</code>, list of single <code>letters</code> (might be repeating) and <code>score</code> of every character.</p>
<p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two or ... | 3 | {
"code": "typedef vector<int> vi;\n\nbool is_usable(string& word, array<int, 26>& letters_cnt) {\n int cnt;\n for (int i = 0; i < 26; i++) {\n cnt = 0;\n for (auto elem : word) if (elem == i + 'a') cnt++;\n if (letters_cnt[i] < cnt) return false;\n }\n return true;\n}\n\nint score_by... |
1,381 | <p>Given a list of <code>words</code>, list of single <code>letters</code> (might be repeating) and <code>score</code> of every character.</p>
<p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two or ... | 3 | {
"code": "typedef vector<int> vi;\n\nbool is_usable(string& word, array<int, 26>& letters_cnt) {\n int cnt;\n for (int i = 0; i < 26; i++) {\n cnt = 0;\n for (auto elem : word) if (elem == i + 'a') cnt++;\n if (letters_cnt[i] < cnt) return false;\n }\n return true;\n}\n\nint score_by... |
1,381 | <p>Given a list of <code>words</code>, list of single <code>letters</code> (might be repeating) and <code>score</code> of every character.</p>
<p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two or ... | 3 | {
"code": "typedef vector<int> vi;\n\nbool is_usable(string& word, array<int, 26>& letters_cnt) {\n int cnt;\n for (int i = 0; i < 26; i++) {\n cnt = 0;\n for (auto elem : word) if (elem == i + 'a') cnt++;\n if (letters_cnt[i] < cnt) return false;\n }\n return true;\n}\n\nint score_by... |
1,381 | <p>Given a list of <code>words</code>, list of single <code>letters</code> (might be repeating) and <code>score</code> of every character.</p>
<p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two or ... | 3 | {
"code": "class Solution {\npublic:\n int maxScoreWords(std::vector<std::string>& words, std::vector<char>& letters, std::vector<int>& score) {\n std::unordered_map<char, int> letterCount;\n for (char letter : letters) {\n letterCount[letter]++;\n }\n\n std::unordered_map<ch... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n vector<vector<int>> out{};\n vector<int> count(nums.size());\n int i, j;\n for (i = 0; i < nums.size(); i++) {\n ++count[nums[i] - 1];\n }\n for (i = 0; i < count.size()... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n int i, j = 0, f = 1, mf = 1;\n for (i = 1 ; i < nums.size() ; i++)\n if (nums[i - 1] == nums[i]) f++;\n else{\n if (mf < f) mf = f... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n vector<vector<int>> ans;\n int n = nums.size();\n\n for(int i=0;i<n;i++){\n int ins = 0;\n for(int j=0;j<ans.size();j++){ /// iterate over each row of ans \n in... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n // Resulting 2D array\n vector<vector<int>> result;\n \n // Iterate over each number in nums\n for (int num : nums) {\n bool placed = false;\n \n // Try to place the element in an existi... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n // Resulting 2D array\n vector<vector<int>> result;\n for (int num :nums)\n {\n bool placed =false;\n\n for(auto& row : result)\n {\n if( find(row.begin(),row.end(), num)==row.en... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "class Solution {\npublic:\n std::vector<std::vector<int>> findMatrix(std::vector<int>& nums) \n {\n std::vector<std::vector<int>> res;\n std::sort(nums.begin(), nums.end());\n\n int prev = nums[0];\n int cur = -1;\n for (auto it : nums)\n {\n if (p... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "class Solution {\npublic:\n inline std::vector<std::vector<int>> findMatrix(std::vector<int>& nums) noexcept\n {\n std::vector<std::vector<int>> res;\n std::sort(nums.begin(), nums.end());\n\n int prev = nums[0];\n int cur = -1;\n for (auto it : nums)\n {\n ... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n vector<vector<int>> res;\n for(int num : nums) {\n bool placed = false;\n for(vector<int>& row : res) {\n if(find(row.begin(), row.end(), num) == row.end() && !placed) {\n... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n vector<vector<int>> ans;\n int maxi=*max_element(nums.begin(),nums.end());\n vector<int> hash(maxi+1,0);\n for(int i:nums){\n hash[i]++;\n }\n int sum=nums.size();\n ... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n vector<vector<int>> res;\n vector<int> count(nums.size() + 1);\n \n for(int i = 0; i < nums.size(); i++) {\n count[nums[i]]++;\n if(count[nums[i]] > res.size())\n ... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n vector<int> freq(nums.size() + 1);\n vector<vector<int>> ans;\n for (auto c : nums){\n if (freq[c] >= ans.size()){\n ans.push_back({});\n }\n\n ans[freq[... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n vector<vector<int>>ans;\n vector<int>freq(nums.size()+1);\n int n=nums.size();\n for(auto c: nums){\n if(freq[c]>=ans.size()){\n ans.push_back({});\n }\n ... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n vector<int> freq(nums.size() + 1);\n\n vector<vector<int>> ans;\n for (int c : nums) {\n if (freq[c] >= ans.size()) {\n ans.push_back({});\n }\n\n // Sto... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n vector<vector<int>>a;\n \n while(nums.size()>0){\n set<int>s;\n for(auto it=nums.begin();it!=nums.end();){\n int val =*it;\n if(... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n map<int, int> mp;\n int maxi = 0;\n\n for (auto i : nums) {\n mp[i]++;\n maxi = max(maxi, mp[i]);\n }\n\n vector<vector<int>> ans(maxi);\n\n for (auto i : mp)... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n int k = 0;\n map <int, int> freq;\n vector <vector <int>> ans;\n\n for (int i = 0; i < nums.size(); i++) {\n if (freq[nums[i]] == k) {\n k++;\n vector <i... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "set<int>st;\nint dd[205];\nclass Solution {\npublic:\n bool check(){\n for(int i=0;i<205;i++){\n if(dd[i]!=0) return false;\n }\n return true;\n }\n vector<vector<int>> findMatrix(vector<int>& nums) {\n vector<vector<int>> ans;\n sort(nums.begin(),nums... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n vector<vector<int>> result;\n // vector<int> table(201, 0);\n map<int, int> visited;\n\n for(int num : nums) {\n if(visited[num] >= result.size()) {\n result.push_back(... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n vector<vector<int>> ans;\n map<int, int> bucket;\n for (auto ele : nums) {\n bucket[ele]++;\n }\n\n while (true) {\n vector<int> vec;\n for (auto ele : bu... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 1 | {
"code": "class Solution {\npublic:\n static bool cmp(pair<int,int>&a,pair<int,int>&b)\n {\n return (a.second>b.second);\n }\n vector<vector<int>> findMatrix(vector<int>& nums) {\n map<int,int>mp;\n for(auto &it:nums)\n {\n mp[it]++;\n }\n vector<pair<... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n unordered_map<int,int> mpp;\n for(auto i:nums){\n mpp[i]++;\n }\n int x = INT_MIN;\n for(auto i:mpp){\n x=max(i.second,x);\n }\n vector<int> v;\n ... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n int n = nums.size();\n unordered_map<int,int> map;\n\n for(int i : nums) {\n map[i]++;\n }\n\n int rows = 0;\n for(auto pair : map) {\n rows = max(rows,pair.s... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n int n = nums.size();\n unordered_map<int,int> map;\n\n for(int i : nums) {\n map[i]++;\n }\n\n int rows = 0;\n for(auto pair : map) {\n rows = max(rows,pair.s... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n unordered_map<int, int> counter;\n\n for (auto &num: nums) {\n counter[num]++;\n }\n\n vector<vector<int>> ans;\n for (auto it = counter.begin(); it != counter.end(); it++) {\n... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n unordered_map<int, int> counts;\n int max_count = 0;\n for (int x : nums) {\n counts[x] += 1;\n max_count = max(max_count, counts[x]);\n }\n\n vector<vector<int>> re... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 1 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n vector<int> table(201, 0);\n int i = 0, j = 0, rows = 0, num = 0;\n int size = nums.size();\n\n for(; i < size; i++) {\n table[nums[i]] += 1;\n }\n for (i = 1; i < table... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 2 | {
"code": "#include <unordered_map>\n#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n int max_count;\n unordered_map<int, int> map;\n // Count the ocurrence of each number\n for (auto num : nums) {\n ... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n vector<vector<int>> result;\n\n vector<int>count(201,0);\n\n bool flag = true;\n\n for(int i =0; i<nums.size(); i++)\n {\n count[nums[i]] += 1;\n }\n\n while(flag... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n unordered_map<int,int> mp;\n vector<vector<int>> result;\n \n for(int i = 0; i < nums.size(); i++) {\n int freq = mp[nums[i]]; // Get frequency of current element\n \n ... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n unordered_map<int,int> mp;\n vector<vector<int>> v;\n for(int i=0;i<nums.size();i++){\n int freq=mp[nums[i]];\n if(freq==v.size()){\n v.push_back({});\n ... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n unordered_map<int,int> mp;\n vector<vector<int>> v;\n for(int i=0;i<nums.size();i++){\n int freq=mp[nums[i]];\n if(freq==v.size()){\n v.push_back({});\n ... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n unordered_map<int, int> freq;\n vector<vector<int>> sol;\n bool allZero = false;\n\n for (int num : nums)\n {\n if (freq.count(num) == 0)\n {\n freq[n... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n unordered_map<int,int> freq;\n for(auto i:nums){\n freq[i]++;\n }\n vector<vector<int>> ans;\n int tot = nums.size();\n while(tot>0){\n vector<int> temp;\n ... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n vector<vector<int>>ans;\n unordered_map<int,int>mp;\n for(auto i:nums)mp[i]++;\n int max1=INT_MIN;\n for(auto i:mp){\n if(i.second>max1)max1=i.second;\n }\n for(i... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n \n\n int count = 0;\n vector<vector<int>>ans;\n int n = nums.size();\n // map<int, int>m;\n\n int start = 0;\n int c = 1;\n map<int, int>m;\n\n\n while(count <... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n unordered_map<int,int> m;\n int n = nums.size();\n\n for(auto i : nums)\n ++m[i];\n\n vector<vector<int>> arr1;\n while (!m.empty()){\n vector<int> arr2, toErase;\n ... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n list<int> lnums(nums.begin(), nums.end());\n unordered_set<int> seen;\n vector<vector<int>> result;\n while (!lnums.empty()) {\n for (auto i = lnums.begin(); i != lnums.end();) {\n ... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n vector<vector<int>>v;\n while(!nums.empty()){\n vector<int> temp;\n set<int> s;\n vector<int> zamen;\n for(int i = 0;i<nums.size();i++){\n if(s.count(nums[i]) == 0... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n \n vector<vector<int>>ans;\n unordered_map<int,int>m;\n for(auto it: nums)\n m[it]++;\n \n while(m.size() > 0)\n {\n vector<int>v, rem;\n for... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\n// unordered_map < int, int> mp;\n// vector <vector<int> > final;\n\n// for(auto x: nums)\n// mp[x]++;\n\n// unordered_set<int> st;\n// st.insert(nums.begin(), nums.end());\n\n// while(true)\n// {\n// bool flag = true; vec... |
2,724 | <p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>
<ul>
<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>
<li>Each row in the 2D array contains <strong>distinct</stron... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> findMatrix(vector<int>& nums) {\nunordered_map < int, int> mp;\nvector <vector<int> > final;\n\nfor(auto x: nums)\nmp[x]++;\n\nunordered_set<int> st;\nst.insert(nums.begin(), nums.end());\n\nwhile(true)\n{\nbool flag = true; vector <int> v;\nfor(auto x : ... |
764 | <p>Given an n-ary tree, return the <em>level order</em> traversal of its nodes' values.</p>
<p><em>Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector<Node*> _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\n v... |
764 | <p>Given an n-ary tree, return the <em>level order</em> traversal of its nodes' values.</p>
<p><em>Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector<Node*> _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npubli... |
764 | <p>Given an n-ary tree, return the <em>level order</em> traversal of its nodes' values.</p>
<p><em>Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong... | 0 | {
"code": "class Solution {\n public:\n\tvector<vector<int>> levelOrder(Node* root)\n\t{\n\t\tvector<vector<int>> res;\n\t\tif (!root)\n\t\t{\n\t\t\treturn {};\n\t\t}\n\n\t\tqueue<Node*> q;\n\t\tq.push(root);\n\n\t\twhile (!q.empty())\n\t\t{\n\t\t\tint size = q.size();\n vector<int> level;\n for... |
764 | <p>Given an n-ary tree, return the <em>level order</em> traversal of its nodes' values.</p>
<p><em>Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector<Node*> _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npubli... |
764 | <p>Given an n-ary tree, return the <em>level order</em> traversal of its nodes' values.</p>
<p><em>Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector<Node*> _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npubli... |
764 | <p>Given an n-ary tree, return the <em>level order</em> traversal of its nodes' values.</p>
<p><em>Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector<Node*> _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npubli... |
764 | <p>Given an n-ary tree, return the <em>level order</em> traversal of its nodes' values.</p>
<p><em>Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong... | 1 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector<Node*> _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npubli... |
764 | <p>Given an n-ary tree, return the <em>level order</em> traversal of its nodes' values.</p>
<p><em>Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong... | 1 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector<Node*> _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npubli... |
764 | <p>Given an n-ary tree, return the <em>level order</em> traversal of its nodes' values.</p>
<p><em>Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector<Node*> _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npubli... |
764 | <p>Given an n-ary tree, return the <em>level order</em> traversal of its nodes' values.</p>
<p><em>Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector<Node*> _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npubli... |
764 | <p>Given an n-ary tree, return the <em>level order</em> traversal of its nodes' values.</p>
<p><em>Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n vector<Node*> children;\n\n Node() {}\n\n Node(int _val) {\n val = _val;\n }\n\n Node(int _val, vector<Node*> _children) {\n val = _val;\n children = _children;\n }\n};\n*/\n\nclass Solution {\npubli... |
766 | <p>You are given a doubly linked list, which contains nodes that have a next pointer, a previous pointer, and an additional <strong>child pointer</strong>. This child pointer may or may not point to a separate doubly linked list, also containing these special nodes. These child lists may have one or more children of th... | 0 | {
"code": "class Solution {\n public:\n Node* flatten(Node* head) {\n for (Node* curr = head; curr; curr = curr->next)\n if (curr->child) {\n Node* cachedNext = curr->next;\n curr->next = curr->child;\n curr->child->prev = curr;\n curr->child = nullptr;\n Node* tail = curr-... |
766 | <p>You are given a doubly linked list, which contains nodes that have a next pointer, a previous pointer, and an additional <strong>child pointer</strong>. This child pointer may or may not point to a separate doubly linked list, also containing these special nodes. These child lists may have one or more children of th... | 1 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* prev;\n Node* next;\n Node* child;\n};\n*/\n\nclass Solution {\npublic:\n Node* flatten(Node* head) {\n for (Node* curr = head; curr; curr = curr->next)\n if (curr->child) {\n Node* cachedNext = curr->... |
766 | <p>You are given a doubly linked list, which contains nodes that have a next pointer, a previous pointer, and an additional <strong>child pointer</strong>. This child pointer may or may not point to a separate doubly linked list, also containing these special nodes. These child lists may have one or more children of th... | 1 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* prev;\n Node* next;\n Node* child;\n};\n*/\n\nclass Solution {\npublic:\n Node* flatten(Node* head) {\n if (!head || (!head->next && !head->child)) {\n return head;\n }\n Node* temp = head... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 0 | {
"code": "class Solution {\npublic:\n\n int minMutation(string startGene, string endGene, vector<string>& bank) {\n int num=0;\n for(int i=0;i<8;i++)\n if(startGene[i]!=endGene[i])\n num++;\n \n queue<pair<string,int>> q;\n q.push(pair<string,int>{s... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 0 | {
"code": "class Solution {\npublic:\n int minMutation(string startGene, string endGene, vector<string>& bank) {\n queue<pair<string,int>>q;\n set<string>st;\n for(auto it:bank)st.insert(it);\n q.push({startGene,0});\n while(q.size()){\n auto it=q.front();\n ... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 0 | {
"code": "// based on the test case\n// endGene must come from the bank\n\nclass Solution {\npublic:\n int minMutation(string startGene, string endGene, vector<string>& bank) {\n if(startGene == endGene)\n return 0;\n \n sort(bank.begin(), bank.end());\n\n auto cmp = [](auto... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 0 | {
"code": "class Solution {\npublic:\n int minMutation(string startGene, string endGene, vector<string>& bank) {\n set<string> s;\n int i;\n for(i=0;i<bank.size();i++)\n {\n s.insert(bank[i]);\n }\n queue<pair<string,int>> q;\n q.push({startGene,0});\n ... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 0 | {
"code": "// class Solution {\n// public:\n// int minMutation(string startGene, string endGene, vector<string>& bank) {\n \n// set<string>set_banks(bank.begin(), bank.end());\n// int ptr1 = 0, ptr2=0;\n// int ans =0;\n// // map< char, pair<char, int> >to_replace;\n// ... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 0 | {
"code": "class Solution {\npublic:\n int minMutation(string startGene, string endGene, vector<string>& bank) {\n unordered_set<string> dict(bank.begin(), bank.end());\n if (!dict.count(endGene))\n return -1;\n if (startGene == endGene)\n return 0;\n dict.erase(st... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 0 | {
"code": "class Solution {\npublic:\n int minMutation(string startGene, string endGene, vector<string>& bank) {\n vector<char>allowed={'A','C','G','T'};\n unordered_set<string>s(bank.begin(),bank.end());\n queue<pair<string,int>>q;\n q.push({startGene,0});\n s.erase(startGene);\... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 1 | {
"code": "class Solution {\npublic:\n int minMutation(string start, string end, vector<string>& bank) {\n unordered_set<string> bankset(bank.begin(), bank.end());\n \n unordered_set<string> visited;\n queue<string> que;\n que.push(start);\n visited.insert(start);\n ... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 1 | {
"code": "class Solution {\npublic:\n int minMutation(string startGene, string endGene, vector<string>& bank) {\n unordered_map<string,bool>visited;\n for(auto &ele:bank)visited[ele]=false;\n visited[startGene]=true;\n queue<string>q;\n q.push(startGene);\n int steps=0;\n... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 2 | {
"code": "class Solution {\npublic:\n int minMutation(string startGene, string endGene, vector<string>& bank) {\n unordered_set<string> dict(bank.begin(), bank.end());\n if (!dict.count(endGene))\n return -1;\n if (startGene == endGene)\n return 0;\n dict.erase(st... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 2 | {
"code": "class Solution {\npublic:\n int minMutation(string startGene, string endGene, vector<string>& bank) {\n unordered_map<string,bool>visited;\n for(auto &ele:bank)visited[ele]=false;\n visited[startGene]=true;\n if(visited.find(endGene)==visited.end())return -1;\n queue<s... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 3 | {
"code": "class Solution {\npublic:\n int minMutation(string start, string end, vector<string>& bank) {\n unordered_set<string> bankset(bank.begin(), bank.end());\n \n unordered_set<string> visited;\n queue<string> que;\n que.push(start);\n visited.insert(start);\n ... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 3 | {
"code": "class Solution {\npublic:\n int minMutation(string startGene, string endGene, vector<string>& bank) {\n unordered_set<string> st;\n st.insert(bank.begin(),bank.end());\n queue<string> q;\n q.push(startGene);\n unordered_set<string> visited;\n visited.insert(star... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 3 | {
"code": "class Solution {\npublic:\n\n int diff(string a,string b){\n int cnt = 0;\n for(int i=0;i<8;i++){\n if(a[i]!=b[i]){\n cnt++;\n }\n if(cnt>1){\n return cnt;\n }\n }\n return cnt;\n }\n\n int solve(... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<string,vector<pair<string,int>>> adj;\n unordered_map<string,int> dist;\n int minMutation(string startGene, string endGene, vector<string>& bank) {\n if(find(bank.begin(),bank.end(),startGene)==bank.end()) bank.push_back(startGene);\n int n =... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 3 | {
"code": "class Solution {\npublic:\n int minMutation(string startGene, string endGene, vector<string>& bank) {\n \n unordered_map<string,int> vis;\n\n queue<string> q;\n\n q.push(startGene);\n\n int nmutes=0;\n string g=\"ACGT\";\n vis[startGene]=1;\n while... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 3 | {
"code": "class Solution {\npublic:\n \n unordered_map<char, vector<char>> mutations = { {{'A'}, {'C','G','T'}}, \n {{'C'}, {'A','G','T'}},\n {{'G'}, {'A','C','T'}},\n ... |
433 | <p>A gene string can be represented by an 8-character long string, with choices from <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, and <code>'T'</code>.</p>
<p>Suppose we need to investigate a mutation from a gene string <code>startGene</code> to a gene string <code>endGene</cod... | 3 | {
"code": "class Solution {\nprivate:\n bool checkAdjacent(string str1, string str2) {\n int charsDifferent = 0;\n for(int i = 0; i < 8; i++) {\n if(str1[i] != str2[i]) {\n charsDifferent++;\n }\n\n if(charsDifferent > 1)\n return false;\... |
434 | <p>Given a string <code>s</code>, return <em>the number of segments in the string</em>.</p>
<p>A <strong>segment</strong> is defined to be a contiguous sequence of <strong>non-space characters</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "Hello... | 0 | {
"code": "class Solution {\npublic:\n int countSegments(string s) {\n if (!s.size()) {\n return 0;\n }\n\n int ans = 0;\n int index = 0;\n while (index < (int)s.size() && s[index] == ' ') {\n index++;\n }\n\n while (index < (int)s.size()) {\n ... |
434 | <p>Given a string <code>s</code>, return <em>the number of segments in the string</em>.</p>
<p>A <strong>segment</strong> is defined to be a contiguous sequence of <strong>non-space characters</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "Hello... | 0 | {
"code": "class Solution {\npublic:\n int countSegments(string s)\n {\n int count = 0;\n\n for (int i = 0; i < s.size(); i++) {\n if (s[i] != ' ')\n count++;\n while (s[i] != ' ' && i < s.size()) {\n i++;\n }\n }\n retur... |
434 | <p>Given a string <code>s</code>, return <em>the number of segments in the string</em>.</p>
<p>A <strong>segment</strong> is defined to be a contiguous sequence of <strong>non-space characters</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "Hello... | 0 | {
"code": "class Solution {\npublic:\n int countSegments(string s) {\n stringstream ss(s);\n string a;\n int i = 0;\n while (ss >> a) {\n ++i;\n }\n return i;\n }\n};",
"memory": "7500"
} |
434 | <p>Given a string <code>s</code>, return <em>the number of segments in the string</em>.</p>
<p>A <strong>segment</strong> is defined to be a contiguous sequence of <strong>non-space characters</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "Hello... | 0 | {
"code": "class Solution {\npublic:\n int countSegments(string s) {\n int count =0;\n for(int i=0; i<s.length(); ++i)\n {\n if((i==0 || s[i-1]==' ') && s[i]!=' ') count++;\n }\n\n return count;\n }\n};",
"memory": "7500"
} |
434 | <p>Given a string <code>s</code>, return <em>the number of segments in the string</em>.</p>
<p>A <strong>segment</strong> is defined to be a contiguous sequence of <strong>non-space characters</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "Hello... | 1 | {
"code": "class Solution {\npublic:\n int countSegments(string s) {\n int cnt = 0;\n for (int i = 0; i < s.length(); i++) {\n if ((i == 0 || s[i-1] == ' ') && s[i] != ' ') {\n cnt++;\n }\n }\n return cnt;\n }\n};\n",
"memory": "7600"
} |
434 | <p>Given a string <code>s</code>, return <em>the number of segments in the string</em>.</p>
<p>A <strong>segment</strong> is defined to be a contiguous sequence of <strong>non-space characters</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = "Hello... | 1 | {
"code": "class Solution {\npublic:\n int countSegments(string s) {\n if(s==\"\"){\n return 0;\n }\n int ctr=0;\n\n string temp=\"\";\n\n for(int i=0;i<s.length();i++){\n if(s[i]==' '){\n if(temp==\"\"){\n continue;\n ... |
435 | <p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>... | 0 | {
"code": "const int ZERO = []() {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n return 0;\n}();\nclass Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n std::sort(intervals.begin(), intervals.end(),\n [](const vector<int>& a, const ... |
435 | <p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>... | 0 | {
"code": "class Solution {\npublic:\n Solution(){\n ios::sync_with_stdio(0);\n cin.tie(0);\n }\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n sort(intervals.begin(),intervals.end());\n int end_of_interval = intervals[0][1];\n int count = 0;\n int si... |
435 | <p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>... | 2 | {
"code": "class Solution {\npublic:\n int func(vector<vector<int>>& intervals, int ind, int prev_end)\n {\n if(ind == intervals.size())\n return 0;\n // int self = 1e9,other=1e9;\n // if(dp[ind]!=-1)\n // return dp[ind];\n if(intervals[ind][0]<prev_end)\n ... |
435 | <p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>... | 2 | {
"code": "class Solution {\npublic:\n int f(vector<vector<int>>& v,int n,int index,int first,int second){\n if(index == n)return 0;\n if(v[index][0] < second){\n first = 1 + f(v,n,index+1,first,min(second,v[index][1]));\n }\n else first = f(v,n,index+1,v[inde... |
435 | <p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>... | 2 | {
"code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n vector<pair<int,int>> inter;\n int n=intervals.size();\n for(int i=0;i<n;i++)\n {\n inter.push_back({intervals[i][0],intervals[i][1]});\n }\n sort(inter.begin(),... |
435 | <p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>... | 2 | {
"code": "\n#include<bits/stdc++.h>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n\n auto customComparator = [] (const pair<int,pair<int,int>>& a, const pair<int,pair<int,int>>& b)\n {\n if(a.second.first == b.second.first)\n ... |
435 | <p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>... | 3 | {
"code": "class Solution {\npublic:\n static bool cmp(pair<int,int> a,pair<int,int> b){\n return a.second<b.second;\n }\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n int n=intervals.size();\n vector<pair<int,int>> v(n);\n int i=0;\n for(auto x:intervals){... |
435 | <p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>... | 3 | {
"code": "class Solution {\npublic:\n static bool sortbysec(pair<int,int> &a,pair<int,int> &b){\n return a.second<b.second;\n }\n int eraseOverlapIntervals(vector<vector<int>>& a) {\n vector<pair<int,int>> nums(a.size());\n int pos=0;\n for(auto i:a){\n nums[pos].first... |
435 | <p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>... | 3 | {
"code": "class Solution {\npublic:\n int eraseOverlapIntervals(vector<vector<int>>& intervals) {\n map<int,int> m;\n for(auto x : intervals){\n if(m.find(x[0]) == m.end()){\n m[x[0]] = x[1];\n }else{\n m[x[0]] = min(m[x[0]],x[1]);\n }\n... |
435 | <p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>... | 3 | {
"code": "class Solution {\npublic:\n int eraseOverlapIntervals(const std::vector<std::vector<int>>& intervals) \n {\n if(intervals.size() < 2)\n {\n return 0;\n }\n\n std::vector<std::vector<int>> intervalsCopy(intervals);\n std::sort(intervalsCopy.begin(), interv... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.