id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n\n void swap(int& x, int& y) \n{ \n int temp = x; \n x = y; \n y = temp; \n} \n\nset< vector<int> >s;\n\n// Function to find the possible \n// permutations \nvoid permutations(vector<vector<int> >& res, \n vector<int> nums, int l, int h) \n{ \n // ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n void per(vector<int> nums, int l, int r, set<vector<int>>&st) {\n if (l == r) {\n st.insert(nums);\n\n return;\n }\n\n else {\n\n for (int i = l; i <= r; i++) {\n \n \n swap(nums[i], nums[l]);\... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n bool used[100];\n vector<int> tmp;\n set<vector<int>> res;\n void Try(int i, vector<int> nums){\n for(int j = 0; j < nums.size(); j++){\n if(!used[j]){\n tmp.push_back(nums[j]);\n used[j] = true;\n if(i =... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n void fun(set<vector<int>>&ans,vector<int>&nums,vector<int>&arr){\n if(nums.size()==0){\n ans.insert(arr);\n return;\n }\n for(int i=0;i<nums.size();i++){\n vector<int>num;\n for(int j=0;j<nums.size();j++){\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n\n void f(vector<int> &v, vector<int> &curr, set<vector<int>> &sol, int n){\n if(curr.size() == n){\n sol.insert(curr);\n return;\n }\n for(int i = 0; i < v.size(); i++){\n curr.push_back(v[i]);\n vector<int> rem... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\n set<vector<int>>v;\n void dfs(vector<int>nums,int i){\n if(i == nums.size()-1){\n v.insert(nums);\n return;}\n dfs(nums, i+1);\n for(int j=i+1;j<nums.size();j++){\n \n swap(nums[i],nums[j]);\n dfs(nums,i+1)... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n\n void backtrack(set<vector<int>>& mySet, vector<int>& remaining, vector<int>& curr){\n\n if(remaining.empty()){\n\n mySet.insert(curr);\n return;\n }\n\n for(int i = 0; i < remaining.size(); i++){\n\n curr.push_back(remai... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n void recursion(set<vector<int>>& v, vector<int>& r, vector<int>& nums, int size)\n {\n if(r.size()==size)\n {\n v.insert(r);\n return;\n }\n if(nums.size()<=0) return;\n for(int i = 0;i<nums.size();i++)\n {\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\n int permLength;\n set<vector<int>> permutations;\n\n void permuteRecurse(vector<int>& curNums, map<int, int>& numFreq) {\n if (curNums.size() == permLength) {\n permutations.insert(curNums);\n return;\n }\n\n vector<int> firstNums;\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n\n void permutationsGenerator(vector<int>& nums, vector<int>& currentCombo, unordered_set<int>& indicesInCombo, set<vector<int>>& permutationSet)\n {\n if((nums.size() == currentCombo.size()))\n {\n permutationSet.insert(currentCombo);\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "\nclass Solution {\npublic:\n void solve(vector<vector<int>>& ans, vector<int>& nums, int start) {\n if (start >= nums.size()) {\n ans.push_back(nums);\n return;\n }\n\n for (int i = start; i < nums.size(); i++) {\n swap(nums[i], nums[start]);\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n void swap(int &a,int &b)\n {\n int temp = a; \n a = b;\n b = temp;\n }\n void solve(vector<vector<int>> &ans,vector<int> &a,int i,int j)\n {\n if(i>=a.size())\n { \n ans.push_back(a);\n return ;\n }... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n\n void helper(int idx,vector<int>&nums,vector<vector<int>>&ans){\n if(idx==nums.size()){\n ans.push_back(nums);\n return;\n }\n for(int i=idx;i<nums.size();i++){\n swap(nums[i],nums[idx]);\n helper(idx+1,nums,ans);\n swap(nums[i],num... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> permuteUnique(vector<int>& nums) {\n if (nums.size() == 1)\n return vector<vector<int>>{nums};\n vector<vector<int>> store{};\n vector<int> cur_step{};\n cur_step.reserve(nums.size());\n perm(store, nums, 0, cu... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n void Permute(vector<int>& nums,int i,vector<vector<int>>& v){\n if (i==nums.size()){\n v.push_back(nums);\n return;\n }\n\n for (int j=i; j<nums.size();j++){\n \n swap(nums[j],nums[i]);\n Permute(nums,... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> permuteUnique(vector<int>& nums) {\n vector<vector<int>> answer;\n vector<int> tempVector;\n vector<bool> usedIndex(nums.size());\n\n backtrack(answer, tempVector, usedIndex, nums);\n\n sort(answer.begin(), answer.end());... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> permuteUnique(vector<int>& nums) {\n \n vector<int> permutation;\n vector<vector<int>> ans;\n vector<bool> used(nums.size(), false);\n set<vector<int>> present;\n\n calculate(nums, permutation, ans, used, present);... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> permuteUnique(vector<int>& nums) {\n \n vector<vector<int>> result;\n vector<int> v;\n vector<bool> visited(nums.size(), false); // To keep track of visited elements\n fxn(nums, v, visited, result);\n\n set<vector... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<int> &nums, vector<int> &perm , vector<bool> used , set<vector<int>> &ans, int idx){\n if(idx==nums.size()){\n ans.insert(perm);\n return;\n }\n for(int i=0;i<nums.size();i++){\n if(used[i]==false){\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<vector<int>>& ans,vector<int>& nums,int i)\n {\n if(i>=nums.size())\n {\n ans.push_back(nums);\n return;\n }\n unordered_map<int,bool> visited;\n\n for(int j=i;j<nums.size();j++)\n {\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n void f(vector<int>& nums,int indx,vector<vector<int>>&res){\n if(indx>=nums.size()){\n res.push_back(nums);\n return ;\n }\n for(int i=indx;i<nums.size();i++){\n swap(nums[indx],nums[i]);\n f(nums,indx+1,res);\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<int> nums, vector<vector<int>> &ans, int index){\n if(index>=nums.size()){\n if(find(ans.begin(), ans.end(), nums) == ans.end()){\n ans.push_back(nums);\n\n }\n return ;\n }\n for(int i=index; ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<int> nums, vector<vector<int>>& ans, int index){\n if(index >= nums.size()){\n for(int i = 0; i<ans.size(); i++){\n if(ans[i] == nums){\n return ;\n }\n }\n ans.push_bac... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\n\n\n private:\n\n void solve(vector<vector<int>> & ans , vector <int> nums , int index) {\n \n //base case\n\n if (index >= nums.size()) {\n int countOccurrence = count(ans.begin() , ans.end() , nums);\n\n if (countOccurrence == 0 ) {\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "\nclass Solution {\nprivate:\n void helper(vector<int> &valTemp,vector<int> &indexTemp, vector<vector<int>> &result, const vector<int> nums)\n {\n if (valTemp.size() == nums.size() && find(result.begin(),result.end(),valTemp)==result.end())\n {\n result.push_back(valTemp);\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\nprivate:\n void solve(vector<int> nums, vector<vector<int>>& a, int index) {\n if (index >= nums.size()) {\n int n = a.size();\n if (n == 0) {\n a.push_back(nums);\n return;\n }\n for (int i = 0; i < n; i+... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> sol; \n vector<vector<int>> permuteUnique(vector<int>& nums) {\n vector<int> temp; \n vector<bool> check(nums.size());\n sort(nums.begin(),nums.end());\n backtrack(temp, nums, check);\n return sol;\n }\n\nprivate:... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\nprivate : \n void solve(vector<int> nums , int index , int size ,set<vector<int>> &ans){\n if(index >= nums.size()){\n ans.insert(nums);\n return ;\n }\n for(int i = index ; i < size ; i++){\n swap(nums[index],nums[i]);\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n set<vector<int>> ans;\n void func(int index,vector<int> nums){\n if(index==nums.size()){\n ans.insert(nums);\n return;\n }\n else{\n for(int i=index;i<nums.size();i++){\n swap(nums[i],nums[index]);\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\nprivate:\n void solve(vector<int> nums, int index, set<vector<int>>& ans) {\n // base case\n if (index >= nums.size()) {\n ans.insert(nums);\n return;\n }\n\n for (int i = index; i < nums.size(); i++) {\n swap(nums[i], nums[i... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\nprivate:\n void solve(vector<int> nums, int index, set<vector<int>>& ans) {\n // base case\n if (index >= nums.size()) {\n ans.insert(nums);\n return;\n }\n\n for (int i = index; i < nums.size(); i++) {\n swap(nums[i], nums[i... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\nvoid solve(set<vector<int>> &st,vector<int> nums,int ind){\n if(ind == nums.size()){\n st.insert(nums);\n return;\n }\n int j=ind;\n while(j<nums.size()){\n swap(nums[ind],nums[j]);\n solve(st,nums,ind+1);\n \n j++;\n }\n}\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n void solve( set<vector<int>>&ans,int index,vector<int> nums){\n if(index>=nums.size()){\n ans.insert(nums);\n }\n for(int i=index;i<nums.size();i++){\n swap(nums[i],nums[index]);\n solve(ans,index+1,nums);\n sw... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\nprivate: \n void solve(vector<int> nums, set<vector<int>>& ans, int index){\n //base case\n if(index >= nums.size()){\n ans.insert(nums);\n return ;\n }\n\n for(int j = index; j<nums.size(); j++){\n swap(nums[index], nums[j]);\n solve(nums,ans,in... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\nprivate:\n void solve(vector<int> nums,set<vector<int>>& ans, int index){\n if(index>=nums.size()){\n ans.insert(nums);\n return;\n } \n for(int j=index; j<nums.size(); j++){\n swap(nums[index],nums[j]);\n solve(nums,an... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n\n void permuteUnique(vector<int> &nums, set<vector<int>> &st, vector<int> temp, int index){\n if(index == nums.size()){\n st.insert(temp);\n return ;\n }\n\n for(int i=index; i<temp.size(); i++){\n swap(temp[index], temp[i... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n\n void permuteUnique(vector<int> &nums, set<vector<int>> &st, vector<int> temp, int index){\n if(index == nums.size()){\n st.insert(temp);\n return ;\n }\n\n for(int i=index; i<temp.size(); i++){\n swap(temp[index], temp[i... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n\n vector<vector<int>>n;\n set<vector<int>>s;\nvoid solve(vector<int>nums,int index)\n{\n if(index==nums.size())\n {\n s.insert(nums);\n return;\n }\n\n for(int i = index ; i < nums.size() ; i++)\n {\n swap(nums[i],nums[index]);\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n bool vis[8];\n map<vector<int>, bool> M;\n vector<int> V;\n vector<vector<int>> ans;\n int N;\n\n void dfs(int i, vector<int> num, int digits) {\n vis[i] = 1; digits--;\n V.push_back(num[i]);\n if (digits == 0) {\n if (!M[V]) {\n... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n void solve(set<vector<int>>&ans,unordered_map<int,int>&mp,vector<int>&res,vector<int>nums){\n if(res.size()==nums.size()){\n ans.insert(res);\n return;\n }\n for(int i=0;i<nums.size();i++){\n if(mp[i]==0){\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n void solve(set<vector<int>>&ans,unordered_map<int,int>&mp,vector<int>&res,vector<int>nums){\n if(res.size()==nums.size()){\n ans.insert(res);\n return;\n }\n for(int i=0;i<nums.size();i++){\n if(mp[i]==0){\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\n set<vector<int>> ans;\n void solve(vector<int>& a, vector<int>& temp, vector<bool>& idx, int n) {\n if (temp.size() == n) {\n ans.emplace(temp);\n return;\n }\n for (int i = 0; i < n; i++) {\n if (!idx[i]) {\n idx... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> permuteUnique(vector<int>& nums) {\n const int n = nums.size();\n unordered_set<string> seen;\n vector<int> curr;\n vector<vector<int>> res;\n unordered_set<int> used;\n function<void(int)> helper = [&](int i) {\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<int>& nums, vector<vector<int>>& ans, int index) {\n if (index >= nums.size()) {\n ans.push_back(nums);\n return;\n }\n\n for (int i = index; i < nums.size(); i++) {\n swap(nums[index], nums[i]);\n ... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\nvoid solve(int idx, int n, vector<int> &nums, vector<vector<int>> &ans) {\n if(idx >= n) {\n ans.push_back(nums);\n return;\n }\n\n for(int i=idx; i<n; i++) {\n swap(nums[i], nums[idx]);\n solve(idx+1, n, nums, ans)... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\n void dfs(vector<int> &nums, vector<int> &indices,\n vector<vector<int>> &result) {\n if (indices.size() >= nums.size()) {\n vector<int> v;\n for (auto i : indices) {\n v.push_back(nums[i]);\n }\n if (find(result.begin(), result.end(), v) == result... |
47 | <p>Given a collection of numbers, <code>nums</code>, that might contain duplicates, return <em>all possible unique permutations <strong>in any order</strong>.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,1,2]
<strong>Output:</strong>
[[1,1,2],
... | 3 | {
"code": "class Solution {\npublic:\n void permuteHelper(vector<int>& nums, vector<vector<int>>& ans, int i) {\n // base case\n if (i >= nums.size()) {\n ans.push_back(nums);\n return;\n }\n\n for (int j = i; j < nums.size(); j++) {\n swap(nums[i], nums... |
48 | <p>You are given an <code>n x n</code> 2D <code>matrix</code> representing an image, rotate the image by <strong>90</strong> degrees (clockwise).</p>
<p>You have to rotate the image <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>, which means you have to modify ... | 0 | {
"code": "class Solution {\npublic:\n void rotate(vector<vector<int>>& matrix) {\n \n int n = matrix.size();\n\n for(int i=0;i<n;i++)\n {\n for(int j=i+1; j<n;j++)\n {\n swap(matrix[i][j],matrix[j][i]);\n }\n\n reverse(matrix[i... |
48 | <p>You are given an <code>n x n</code> 2D <code>matrix</code> representing an image, rotate the image by <strong>90</strong> degrees (clockwise).</p>
<p>You have to rotate the image <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>, which means you have to modify ... | 0 | {
"code": "class Solution {\npublic:\n void rotate(vector<vector<int>>& matrix) {\n for(int i=0;i<matrix.size();i++){\n for(int j=i;j<matrix.size();j++){\n int temp=matrix[i][j];\n matrix[i][j]=matrix[j][i];\n matrix[j][i]=temp;\n }\n ... |
48 | <p>You are given an <code>n x n</code> 2D <code>matrix</code> representing an image, rotate the image by <strong>90</strong> degrees (clockwise).</p>
<p>You have to rotate the image <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>, which means you have to modify ... | 0 | {
"code": "class Solution {\npublic:\n void rotate(vector<vector<int>>& matrix) {\n int n = matrix.size();\n for(int i = 0; i<n; i++) {\n for(int j = 0; j<i; j++) {\n swap(matrix[i][j], matrix[j][i]);\n }\n }\n \n for(int i = 0; i<n; i++) {\n ... |
48 | <p>You are given an <code>n x n</code> 2D <code>matrix</code> representing an image, rotate the image by <strong>90</strong> degrees (clockwise).</p>
<p>You have to rotate the image <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>, which means you have to modify ... | 0 | {
"code": "class Solution {\npublic:\n void rotate(vector<vector<int>>& matrix) {\n \n// to rotate the matrix we have to first transpose the matrix and then reverse the row \n \n int row=matrix.size();\n int col=matrix[0].size();\n for(int i=0;i<row;i++){\n \n ... |
48 | <p>You are given an <code>n x n</code> 2D <code>matrix</code> representing an image, rotate the image by <strong>90</strong> degrees (clockwise).</p>
<p>You have to rotate the image <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>, which means you have to modify ... | 1 | {
"code": "class Solution {\npublic:\n void rotate(vector<vector<int>>& matrix) {\n int m = matrix.size(), n = matrix[0].size();\n for(int i = 0; i < m; i++)\n {\n for(int j = i; j < n; j++)\n std :: swap(matrix[i][j], matrix[j][i]);\n reverse(matrix[i].beg... |
48 | <p>You are given an <code>n x n</code> 2D <code>matrix</code> representing an image, rotate the image by <strong>90</strong> degrees (clockwise).</p>
<p>You have to rotate the image <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a>, which means you have to modify ... | 1 | {
"code": "class Solution {\npublic:\n void rotate(vector<vector<int>>& matrix) {\n for(int i = 0; i < matrix.size(); i++)\n {\n for(int j = i; j < matrix[i].size(); j++)\n std :: swap(matrix[i][j], matrix[j][i]);\n reverse(matrix[i].begin(), matrix[i].end());\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "\n\nstruct Solution {\n constexpr vector<vector<string>>\n groupAnagrams(const vector<string>& strs) const {\n return {};\n }\n};\n\nint init = [] {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n\n constexp... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "\n\nstruct Solution {\n constexpr vector<vector<string>>\n groupAnagrams(const vector<string>& strs) const {\n return {};\n }\n};\n\nint init = [] {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n\n constexp... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "\n\nstruct Solution {\n constexpr vector<vector<string>>\n groupAnagrams(const vector<string>& strs) const {\n return {};\n }\n};\n\nint init = [] {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n\n ofstream out(\"user.out\");\n cout.rdbuf(out.rdbuf());\n\n constexp... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "constexpr array<char, 26> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23,\n 29, 31, 37, 41, 43, 47, 53, 59, 61,\n 67, 71, 73, 79, 83, 89, 97, 101};\n\nstruct Solution {\n vector<vector<string>> groupAnagrams(const vector<string>& strs) ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "constexpr array<char, 26> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23,\n 29, 31, 37, 41, 43, 47, 53, 59, 61,\n 67, 71, 73, 79, 83, 89, 97, 101};\n\nstruct Solution {\n vector<vector<string>> groupAnagrams(const vector<string>& strs) ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "constexpr char primes[26] = {2, 3, 5, 7, 11, 13, 17, 19, 23,\n 29, 31, 37, 41, 43, 47, 53, 59, 61,\n 67, 71, 73, 79, 83, 89, 97, 101};\n\nstruct Solution {\n constexpr vector<vector<string>> groupAnagrams(const vector<string>& str... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "constexpr array<char, 26> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23,\n 29, 31, 37, 41, 43, 47, 53, 59, 61,\n 67, 71, 73, 79, 83, 89, 97, 101};\n\nstruct Solution {\n vector<vector<string>> groupAnagrams(const vector<string>& strs) ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "constexpr array<char, 26> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23,\n 29, 31, 37, 41, 43, 47, 53, 59, 61,\n 67, 71, 73, 79, 83, 89, 97, 101};\n\nstruct Solution {\n vector<vector<string>> groupAnagrams(const vector<string>& strs) ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "constexpr array<char, 26> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23,\n 29, 31, 37, 41, 43, 47, 53, 59, 61,\n 67, 71, 73, 79, 83, 89, 97, 101};\n\nstruct Solution {\n vector<vector<string>> groupAnagrams(const vector<string>& strs) ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "constexpr array<char, 26> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23,\n 29, 31, 37, 41, 43, 47, 53, 59, 61,\n 67, 71, 73, 79, 83, 89, 97, 101};\n\nstruct Solution {\n vector<vector<string>> groupAnagrams(const vector<string>& strs) ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "constexpr array<char, 26> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23,\n 29, 31, 37, 41, 43, 47, 53, 59, 61,\n 67, 71, 73, 79, 83, 89, 97, 101};\n\nstruct Solution {\n vector<vector<string>> groupAnagrams(const vector<string>& strs) ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "constexpr array<char, 26> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23,\n 29, 31, 37, 41, 43, 47, 53, 59, 61,\n 67, 71, 73, 79, 83, 89, 97, 101};\n\nstruct Solution {\n vector<vector<string>> groupAnagrams(const vector<string>& strs) ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "constexpr array<char, 26> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23,\n 29, 31, 37, 41, 43, 47, 53, 59, 61,\n 67, 71, 73, 79, 83, 89, 97, 101};\n\nstruct Solution {\n vector<vector<string>> groupAnagrams(const vector<string>& strs) ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "constexpr array<char, 26> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23,\n 29, 31, 37, 41, 43, 47, 53, 59, 61,\n 67, 71, 73, 79, 83, 89, 97, 101};\n\nstruct Solution {\n vector<vector<string>> groupAnagrams(const vector<string>& strs) ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<vector<string>> v;\n v.push_back({strs[0]});\n for(int i=1;i<strs.size();i++){\n int a=1;\n unordered_map<char,int> map;\n\n for(int j=0;j<v.size();j++)... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "template <std::size_t N>\nstruct character_frequencies {\n character_frequencies(const std::string& string) {\n for (const char character : string) {\n ++frequencies[character - 'a'];\n }\n }\n\n char frequencies[N] = {0};\n};\n\ntemplate <std::size_t N>\nbool operator==(const character_frequ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) { \n vector<vector<string>> ans;\n vector<string> gr;\n int sz = strs.size(); \n vector<bool> done(sz,0);\n int chr[26] = {};\n for(int i = 0 ; i < sz ; i++){\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n inline vector<vector<string>> groupAnagrams(const vector<string>& strs) const {\n vector<vector<string>> ans;\n vector<string> gr;\n int sz = strs.size(); \n vector<bool> done(sz,0);\n int chr[26] = {};\n for(int i = 0 ; i < sz ; i... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n bool isAnagram(std::string a, std::string b)\n {\n if (a.size() != b.size()) return false;\n\n int hash[26] = {0};\n for (int i = 0; i < a.size(); i++)\n {\n hash[a[i] - 97]++;\n }\n for (int i = 0; i < b.size(); i++)\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& s) {\n long long ioi[26];\n ioi[0]=1;\n for(int i=1;i<26;i++){\n ioi[i]=ioi[i-1]*199%1000000000039;\n }\n vector<long long> h(s.size(),0);\n long long count;\n for(i... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) { \n vector<vector<string>> ans;\n vector<string> gr;\n int sz = strs.size(); \n vector<bool> done(sz,0);\n int chr[26] = {};\n for(int i = 0 ; i < sz ; i++){\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "constexpr array<char, 26> primes = {\n 2, 3, 5, 7, 11, 13, 17, 19, 23,\n 29, 31, 37, 41, 43, 47, 53, 59, 61,\n 67, 71, 73, 79, 83, 89, 97, 101\n};\n\nclass Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<double, vector<string>> data(... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<string> dups = strs;\n vector<string> group;\n vector<vector<string>> ans;\n for(int i=0; i<strs.size(); i++){\n sort(strs[i].begin(), strs[i].end());\n }\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "\n// class Solution {\n// public:\n// vector<vector<string>> groupAnagrams(vector<string>& strs) {\n// unordered_map<string, vector<string>> ans;\n\n// for (string& s : strs) {\n// string key = s;\n// sort(key.begin(), key.end());\n// ans[key].push_ba... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n bool isAnagram(std::string a, std::string b)\n {\n if (a.size() != b.size()) return false;\n\n int hash[26] = {0};\n for (int i = 0; i < a.size(); i++)\n {\n hash[a[i] - 97]++;\n }\n for (int i = 0; i < b.size(); i++)\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n for (int i = 0; i < strs.size(); i++) {\n string orig = strs[i];\n sort(strs[i].begin(), strs[i].end());\n strs[i] += '|' + orig;\n }\n \n sort(strs.beg... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "constexpr array<char, 26> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23,\n 29, 31, 37, 41, 43, 47, 53, 59, 61,\n 67, 71, 73, 79, 83, 89, 97, 101};\n\nstruct Solution {\n inline vector<vector<string>> groupAnagrams(const vector<string>&... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>&v) {\n int n=v.size();\n vector<pair<string,int>>store(n);\n\n for(int i=0;i<n;i++){\n string k=v[i];\n sort(k.begin(),k.end());\n store[i]={k,i};\n\n }\n \n \n sort(store.begin... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>&v) {\n int n=v.size();\n vector<pair<string,int>>store(n);\n\n for(int i=0;i<n;i++){\n string k=v[i];\n sort(k.begin(),k.end());\n store[i]={k,i};\n\n }\n \n \n sort(store.begin... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "constexpr char primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101 };\n\nstruct Solution {\n inline vector<vector<string>> groupAnagrams(const vector<string>& strs) const\n {\n std::unordered_map<double, vector<string>> hashMap;\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n map<long long, vector<string>> groups;\n int hast_arr[26] = {643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821};\n ... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n using hash = array<uint8_t, 26>;\n \n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<hash> keys;\n vector<vector<string>> anagrams;\n for (const string& s: strs) {\n hash x = get_hash(s);\n auto [lit, uit... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "struct Solution {\n inline vector<vector<string>> groupAnagrams(vector<string> strs) const\n {\n static constexpr char primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101 };\n std::unordered_map<double, vector<string>> hashMap... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n int n = strs.size();\n vector<vector<string>> ans(n);\n unordered_map<string, int> m;\n int k = 0;\n for(int i = 0; i < n; i++) {\n string s = strs[i];\n so... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n using hash = array<uint8_t, 26>;\n \n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n map<hash, vector<string>> X;\n for (string& s: strs) {\n X[get_hash(s)].push_back(std::move(s));\n }\n vector<vector<string>> anag... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n using hash = array<uint8_t, 26>;\n \n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n map<hash, vector<string>> X;\n for (string& s: strs) {\n X[get_hash(s)].push_back(std::move(s));\n }\n vector<vector<string>> anag... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<vector<string>>result;\n vector<string> temp = strs;\n for(string& s:temp)sort(s.begin(),s.end());\n for(int i = 0;i<temp.size();i++){\n if(temp[i] == \" \")continue;\... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<vector<string>> v;\n if(strs.size()==0) return v;\n else if(strs.size()==1){\n v.push_back(strs);\n return v;\n }\n else{\n vector<string>... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, vector<string>> anagrams{};\n for (auto &s : strs) {\n auto copy = s;\n ranges::sort(copy);\n anagrams[copy].push_back(std::move(s));\n }... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<vector<string>> v;\n if(strs.size()==0) return v;\n else if(strs.size()==1){\n v.push_back(strs);\n return v;\n }\n else{\n vector<string>... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<vector<string>> v;\n if(strs.size()==0) return v;\n else if(strs.size()==1){\n v.push_back(strs);\n return v;\n }\n else{\n vector<string>... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<vector<string>> v;\n if(strs.size()==0) return v;\n else if(strs.size()==1){\n v.push_back(strs);\n return v;\n }\n else{\n vector<string>... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<vector<string>> v;\n if(strs.size()==0) return v;\n else if(strs.size()==1){\n v.push_back(strs);\n return v;\n }\n else{\n vector<string>... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n unordered_map<string, int> hash; // Map to store sorted string to index\n int count = 0;\n int size = strs.size();\n\n // Create a temporary copy of the strings\n vector<string>... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<vector<string>> v;\n if(strs.size()==0) return v;\n else if(strs.size()==1){\n v.push_back(strs);\n return v;\n }\n else{\n vector<string>... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<vector<string>> res;\n unordered_map<string, int> m;\n for(int i=0; i<strs.size(); i++){\n string t=strs[i];\n sort(t.begin(), t.end());\n if(!m.count(t... |
49 | <p>Given an array of strings <code>strs</code>, group the <span data-keyword="anagram">anagrams</span> together. You can return the answer in <strong>any order</strong>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io"... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<string>> groupAnagrams(vector<string>& strs) {\n vector<vector<string>> ans;\n unordered_map<string,int> list;\n int ind=1;\n for(auto i:strs){\n string temp=i;\n sort(temp.begin(),temp.end());\n if(li... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.