id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "template<typename T>\nvoid print_set(string_view message, const T& collection, string_view end=\"\");\n\ntemplate<typename T>\nvoid print_set(string_view message, const std::set<T>& item_collection, string_view end) {\n std::cout << message <<\"[\";\n auto it = item_collection.begin();\n if (it !=...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> output;\n int n, k;\n void backtrack(int first, vector<int> curr, vector<int>& nums) {\n // if the combination is done\n if (curr.size() == k) output.push_back(curr);\n for (int i = first; i < n; ++i) {\n // add i into...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> output;\n int n, k;\n void backtrack(int first, vector<int> curr, vector<int>& nums) {\n // if the combination is done\n if (curr.size() == k) output.push_back(curr);\n for (int i = first; i < n; ++i) {\n // add i into...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n void backtrack(int targetSize, int begin, vector<int> curr, const vector<int>& nums,\n vector<vector<int>>& output) {\n if (curr.size() == targetSize) {\n output.emplace_back(curr);\n }\n for (int i = begin; i < nums.size(); ++i) {\n ...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\n\npublic:\n\n vector<vector<int>> output;\n\n int n, k;\n\n void backtrack(int first, vector<int> curr, vector<int>& nums) {\n\n // if the combination is done\n\n if (curr.size() == k) output.push_back(curr);\n\n for (int i = first; i < n; ++i) {\n\n ...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n int n = (int)nums.size();\n vector<vector<int>> result;\n vector<int> sol;\n core(0,n,result,sol,nums);\n return result;\n\n }\nprivate:\n void core(int i,int n,vector<vector<int>>& result, vector<int>& s...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n std::vector<std::vector<int>> res;\n std::vector<int> cur;\n dfs(nums, 0, cur, res);\n return res;\n }\n\n void dfs(const vector<int>& nums, int i, std::vector<int>& cur, std::vector<std::vec...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n\n void rec(vector<int>& nums, vector<vector<int>>& ans, vector<int>& temp, int idx) {\n int n = nums.size();\n if (idx==n) {\n ans.push_back(temp);\n return;\n }\n rec(nums, ans, temp, idx+1);\n temp.push_back(nums[idx]...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n void generate(vector<vector<int>>& ans, vector<int>& nums, vector<int>& x, int i) {\n if (i == nums.size()) {\n ans.push_back(x); \n return;\n }\n\n generate(ans, nums, x, i + 1);\n\n x.push_back(nums[i]);\n generate(a...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n void Recur(int ind,int n,vector<int>&a,vector<int>&temp,vector<vector<int>>&ans)\n {\n if(ind==n)\n {\n ans.push_back(temp);\n return;\n }\n Recur(ind+1,n,a,temp,ans);\n temp.push_back(a[ind]);\n Recur(ind+1,n...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\nvoid func(vector<vector<int>> &ans,vector<int> & temp,vector<int>& nums,int k,int n)\n{\n if(k==n)\n {\n ans.push_back(temp);\n return;\n }\n \n func(ans,temp,nums,k+1,n);\n temp.push_back(nums[k]);\n func(ans,temp,nums,k+1,n);\n temp.pop_back();...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\n\n vector<vector<int>> ans;\n void generate(vector<int> &subset,int i, vector<int> &nums){\n if(i==nums.size()){\n ans.push_back(subset);\n return; \n }\n generate(subset,i+1,nums);\n subset.push_back(nums[i]);\n genera...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> allsoln;\n vector<int> intermsoln;\n\n void rec(vector<int>& nums, int level){\n if(level==nums.size()){\n allsoln.push_back(intermsoln);\n return;\n }\n\n rec(nums, level+1);\n intermsoln.push_back(nums[level]);\n rec(num...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n void create(int index, vector<int> &nums,vector<vector<int>> &res,vector<int> & subset)\n {\n if(index>=nums.size())\n {\n res.push_back(subset);\n return;\n }\n create(index+1,nums,res,subset);\n subset.push_back(nu...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> allsoln;\n vector<int> intermsoln;\n\n void rec(vector<int>& nums, int level){\n if(level==nums.size()){\n allsoln.push_back(intermsoln);\n return;\n }\n\n rec(nums, level+1);\n intermsoln.push_back(nums[level]);\n rec(num...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> ans;\n vector<vector<int>> subsets(vector<int>& nums) {\n vector<int> temp;\n powSet(nums, temp, 0);\n return ans;\n }\n\n void powSet(vector<int>& nums, vector<int>& temp, int i) {\n if(i == nums.size()) {\n ...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n void printSubsequences(int i, vector<int>& nums, vector<int>& sub, vector<vector<int>>& res) {\n if(i == nums.size()) {\n if(sub.size() == 0) res.push_back({});\n else res.push_back(sub);\n return;\n }\n // not take\n ...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n void generatePowerSet(vector<int>& nums, vector<int>& currentSet, int index,\n vector<vector<int>>& powerSet) {\n if (index == nums.size()) {\n powerSet.push_back(currentSet);\n return;\n }\n generatePowerSet...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n vector<vector<int>> ans;\n int n=(int)nums.size();\n vector<int> vec(n,0);\n function<void(int,int)> comb=[&ans,&n,&vec,&comb,&nums](int t,int s){\n if(t==n){\n ans.empla...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n TreeNode* root = new TreeNode(100);\n root = generateTree(root, nums, 0);\n \n //nums.insert(nums.begin(), 0);\n generateSubsets(root);\n\n return ans;\n }\nprivate:\n vector<ve...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n void solve(set<vector<int>>&ans,vector<int>&curr,int i,int n,vector<int>&nums){\n ans.insert(curr);\n if(i==n){\n return ;\n }\n curr.push_back(nums[i]);\n solve(ans,curr,i+1,n,nums);\n curr.pop_back(); \n sol...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\nprivate: void solve(vector<int>& ip, vector<int>& op, vector<vector<int>>& result)\n {\n if(ip.size() == 0)\n {\n result.push_back(op);\n return;\n }\n op.push_back(ip[0]);\n vector<int> ip1(ip.begin()+1,ip.end());\n solve...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n\n void subsetHelper(set<vector<int>> &res, int start, vector<int> &curr, vector<int> &nums){\n //Base Case\n\n if(start == nums.size()){\n res.insert(curr);\n return;\n }\n\n //exclusion\n subsetHelper(res, start+1, cur...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n string stringify(vector<int> v) {\n string s;\n for (int i : v) {\n s += to_string(i) + ' ';\n }\n return s;\n }\n\n vector<vector<int>> res;\n void backtrack(vector<int> options, vector<int> comb, int start, int n) {\n r...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n\nset<vector<int>> s;\nint n;\n\nvoid getSubsets(int i, vector<int>& nums, vector<int>& temp){\n if(i==n){\n s.insert(temp);\n return;\n }\n\n getSubsets(i+1,nums,temp);\n temp.push_back(nums[i]);\n getSubsets(i+1,nums,temp);\n temp.pop_back();\n}\...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n void recans(int st, vector<int>& a, set<vector<int>>& s, vector<int>& nums) {\n // Base case: if index exceeds size, stop the recursion\n if (st == nums.size()) {\n s.insert(a);\n return;\n }\n\n // Insert current subset into ...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n void combo(int i,vector<int> &temp,vector<int> nums,vector<vector<int>> &res){\n if(i==0){\n res.push_back(temp);\n temp.push_back(nums[i]);\n res.push_back(temp);\n temp.pop_back();\n return;\n }\n t...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\nset<vector<int>>ans;\n void solve(vector<int>& nums, int ind, vector<int>&val) {\n if(ind == nums.size()) {\n return;\n }\n val.push_back(nums[ind]);\n solve(nums, ind+1, val);\n ans.insert(val);\n val.pop_back();\n s...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n void subst(vector<int>& nums,vector<vector<int>>& v,int i)\n {\n if(i==nums.size()||nums.empty()) return;\n else\n {\n vector<int> temp = nums;\n subst(nums,v,i+1);\n temp.erase(temp.begin()+i);\n v.push_back...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> result;\n int n;\n unordered_set<int> st;\n void solve(int i, vector<int>& temp, vector<int>& nums) {\n if (i >= n) {\n result.push_back(temp);\n return;\n }\n // for(int i = index ; i<n; i++){\n i...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n void solve(vector<int>&nums,vector<vector<int>>&ans,int ind,int n,vector<int>&ans1)\n {\n if(ind==n)\n {\n ans.push_back(ans1);\n return ;\n }\n vector<int>ans2 = ans1;\n ans2.push_back(nums[ind]);\n solve(num...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n vector<vector<int>> ans;\n vector<int> curr;\n func(ans, curr, nums);\n return ans;\n\n }\n\n void func(vector<vector<int>>& ans, vector<int>& curr,vector<int>& nums) {\n if (curr.size...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n vector<vector<int>> results;\n vector<bool> choices;\n dfs(0, choices, nums, results); // 從索引 0 開始 DFS\n return results;\n }\n void dfs(int i, vector<bool>& choices, vector<int>& nums, vector...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> ans;\n void gg(vector<int> &a, int idx, vector<int> &temp){\n if(idx == a.size()){\n ans.push_back(temp);\n return;\n }\n auto KK = temp;\n temp.push_back(a[idx]);\n gg(a,idx+1,temp);\n gg(...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n // vector<vector<int>> subsets(vector<int>& nums) {\n // vector<vector<int>> new_nums;\n // subsets_helper(nums, 0, {}, new_nums);\n // return new_nums;\n // }\n\n // void subsets_helper(vector<int>&nums, int index, vector<int>current, vector<vector...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\nvoid subsequence(vector<int>arr, int index, int n, vector<vector<int>> &ans, vector<int>&temp)\n{\n if (index == n)\n {\n ans.push_back(temp);\n return;\n }\n // Not included\n subsequence(arr, index + 1, n, ans, temp);\n // yes included\n temp....
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\nprivate: \n void generateSubset(vector<int> nums, vector<int>& subset, int idx, vector<vector<int>>& ans){\n // base case\n if(idx == nums.size()){\n ans.push_back(subset);\n return;\n }\n\n generateSubset(nums, subset, idx + 1, ans);\n...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
2
{ "code": "class Solution {\npublic:\n\n void powerSet(vector<int>nums,int n,int i,vector<int>&temp,vector<vector<int>>&ans)\n {\n if(i==n)\n {\n ans.push_back(temp);\n return;\n }\n\n //don't include \n powerSet(nums,n,i+1,temp,ans);\n temp.push_b...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
3
{ "code": "class Solution {\npublic:\nvector<vector<int>> ans;\n void func(int ind,vector<int> &nums,vector<int> arr){\n if(ind == nums.size()){\n ans.push_back(arr);\n return;\n }\n arr.push_back(nums[ind]);\n func(ind + 1,nums,arr);\n arr.pop_back();\n ...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
3
{ "code": "class Solution {\npublic:\n void helper(vector <int> &nums, vector <int> ans, vector <vector<int>> &FinalAns, int idx)\n { \n if(idx == nums.size())\n {\n FinalAns.push_back(ans);\n return ;\n }\n helper(nums, ans, FinalAns, idx + 1);\n\n ans...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
3
{ "code": "class Solution {\n vector<vector<int>>ans;\npublic:\nvoid func(int ind,vector<int>& nums,vector<int>v)\n{\n \n if(ind>=nums.size())\n {\n ans.push_back(v);\n return;\n }\n v.push_back(nums[ind]);\n func(ind+1,nums,v);\n v.pop_back();\n func(ind+1,nums,v);\n}\n ve...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
3
{ "code": "class Solution {\n vector<vector<int>>ans;\npublic:\nvoid func(int ind,vector<int>& nums,vector<int>v)\n{\n \n if(ind==nums.size())\n {\n ans.push_back(v);\n return;\n }\n v.push_back(nums[ind]);\n func(ind+1,nums,v);\n v.pop_back();\n func(ind+1,nums,v);\n}\n ve...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
3
{ "code": "class Solution {\npublic:\n set<vector<int>> totalSubsets;\n\n vector<vector<int>> subsets(vector<int>& nums) {\n\n if(nums.size() == 0) {\n return {};\n }\n\n backtrack(nums, {}, {});\n\n vector<vector<int>> ans;\n for(vector<int> s : totalSubsets) {\n ...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
3
{ "code": "class Solution {\npublic:\n set<vector<int>> res;\n void recursiveTree(vector<int>&nums, vector<int> temp, int idx){\n if(idx==nums.size()){\n res.insert(temp);\n return;\n }\n temp.push_back(nums[idx]);\n recursiveTree(nums,temp, idx+1);\n te...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n vector<vector<int>> res;\n vector<int> curr;\n\n dfs(nums, 0, res, curr);\n set<vector<int>> setRes(res.begin(), res.end());\n vector<vector<int>> ret(setRes.begin(), setRes.end());\n ...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
3
{ "code": "#include<bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n vector<vector<int>> ans;\n string ip(nums.size(), ' '); // Create a string of size nums.size() filled with spaces\n for(int i = 0; i < nums.size(); i++){\...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
3
{ "code": "#include<bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n vector<vector<int>> ans;\n string ip(nums.size(), ' '); // Create a string of size nums.size() filled with spaces\n for(int i = 0; i < nums.size(); i++){\...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
3
{ "code": "class Solution {\npublic:\nvoid subset(vector<int>input,vector<int>&output,vector<vector<int>>&result){\n if(input.size()==0){\n result.push_back(output);\n return ;\n }\n vector<int> output1 = output;\n vector<int> output2 = output;\n output2.push...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> subsets(vector<int>& nums) {\n vector<vector<int>> res;\n vector<int> k;\n res.push_back(k);\n reverse(nums.begin(),nums.end());\n su(res,nums,k);\n return res;\n \n }\n void su(vector<vector<int>>& re...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
3
{ "code": "class Solution {\npublic:\n void solve(vector<vector<int>> &ans, vector<int> nums,\n vector<int> &res) {\n if (nums.size() == 0) {\n ans.push_back(res);\n return;\n }\n vector<int> op1=res;\n vector<int> op2=res;\n\n o...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
3
{ "code": "class Solution {\n private:\n void solve(vector<int> nums,vector<int> output,int index,vector<vector<int>>& ans){\n if(index>=nums.size()){\n ans.push_back(output);\n return;\n }\n solve(nums,output,index+1,ans);\n\n int element=nums[index];\n ...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
3
{ "code": "class Solution {\nprivate:\n void f(int n,int i,vector<int> nums,vector<vector<int>>& ans,vector<int> out){\n if(i==n){\n ans.push_back(out);\n return;\n }\n //exclude\n f(n,i+1,nums,ans,out);\n //include\n out.push_back(nums[i]);\n ...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
3
{ "code": "class Solution {\n private:\n void solve(vector<int>nums, vector<int>output, int index, vector<vector<int>>&ans)\n {\n if(index>=nums.size()){\n ans.push_back(output);\n return;\n }\n solve(nums,output,index+1,ans);\n int element=nums[index];\n ...
78
<p>Given an integer array <code>nums</code> of <strong>unique</strong> elements, return <em>all possible</em> <span data-keyword="subset"><em>subsets</em></span> <em>(the power set)</em>.</p> <p>The solution set <strong>must not</strong> contain duplicate subsets. Return the solution in <strong>any order</strong>.</p>...
3
{ "code": "class Solution {\npublic:\nvoid subsequence(vector<int>arr, int index, int n, vector<vector<int>> &ans, vector<int> temp)\n{\n if (index == n)\n {\n ans.push_back(temp);\n return;\n }\n // Not included\n subsequence(arr, index + 1, n, ans, temp);\n // yes included\n temp....
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
0
{ "code": "class Solution {\n public:\n bool exist(vector<vector<char>>& board, string word) {\n for (int i = 0; i < board.size(); ++i)\n for (int j = 0; j < board[0].size(); ++j)\n if (dfs(board, word, i, j, 0))\n return true;\n return false;\n }\n\n private:\n bool dfs(vector<vector<ch...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
0
{ "code": "class Solution {\npublic:\n bool exist(vector<vector<char>>& board, string word) {\n int rows = board.size();\n int cols = board[0].size();//board[0] refers to the first row of the grid, which is a vector<char>.\n // board[0].size() returns the number of columns (or the ...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool calculate(vector<vector<char>>& board, string word, map<pair<int,int>, int>& mp, pair<int,int> curr, int idx) {\n if(curr.first >= board.size() || curr.second>= board[0].size() || idx>= word.length()\n || curr.first < 0 || curr.second < 0) {\n ...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool exist(vector<vector<char>>& board, string word) {\n if (board[0][0] == word[0]) \n reverse(word.begin(), word.end());\n int m = board.size();\n int n = board[0].size();\n \n if (word.length() > n * m) return false; // Optimiz...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool myfunc(vector<vector<char>> board, string word,int r=0,int c=0) {\n //base condition for word found\n if(word.size()==0) return true;\n int R,C;\n R=board.size();\n C=board[0].size();\n //base conditions for word not found\n ...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n \n bool mySearchWord(int nIndex, int nSize,int nX, int nY, int nSizeX, int nSizeY,string sTarget, vector<vector<bool>>visited, vector<vector<char>>& board) {\n if (nY < 0 || nX < 0 || nX > nSizeX-1 || nY > nSizeY-1 || board[nY][nX] != sTarget[nIndex] || visited[nY][...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n\n bool dfs(int i, int j, vector<vector<char>>& board, string word, int n, int m, string &temp, int cnt){\n if(cnt == word.length()) return true;\n\n if(i<0 || i>=n || j<0 || j>=m || board[i][j] == '.'){\n return false;\n }\n\n char ch = ...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n\n struct Node\n {\n Node(){}\n unordered_map<char, Node*> child; \n };\n \n Solution():dr{0, 0, -1, 1}, dc{1, -1, 0, 0}\n {\n root = new Node();\n }\n \n void build_trie(vector<vector<char>> &board, int r, int c, int len, Node *no...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "void search(vector<vector<char>>board,string word,int i,int j,int pos,string result,vector<vector<int>> check,vector<bool> & output){\n if(result == word){\n output.push_back(true);\n return;\n }\n string temp = result;\n int repeat = 0;\n if((i-1) != -1){\n if(board[i-1...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool solve(vector<vector<char>> board, string word, int i, int j, int n){\n \n if(n==word.size()) return true;\n if(i<0 || j<0 || i>=board.size() || j>=board[0].size()) return false;\n \n if(board[i][j] == '0') return false;\n if(boar...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n \n bool dfs(vector<vector<char>>& board, string &word, int index, string &cur, int x, int y){\n if(index == word.size()){\n return true;\n }\n if(x<0 || y<0 || x>= board.size() || y >= board[0].size()){\n return false;\n }\...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\n // struct that represents a step of the BFS algorithm\n struct Position {\n int i, j;\n const char *ptr;\n unordered_set<int> visited;\n\n /* CONSTRUCTOR */\n Position(int i, int j, const std::string &word)\n : i(i), j(j), ptr(word.c_st...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool check(vector<vector<char>>& board, string& word, int index, int row, int col) {\n if (index == word.size()) { return true; }\n\n vector<pair<int, int>> directions = {{0,1}, {0,-1}, {1,0}, {-1,0}};\n for (pair<int, int> direction : directions) {\n ...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool exist(vector<vector<char>>& board, string word) {\n\n if(!solvable(board, word)) {\n return false;\n }\n\n // cout << \"Solvable\\n\";\n\n if(shouldReverse(word)) {\n reverse(word.begin(), word.end());\n // cou...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\nprivate:\n \n unordered_set<int> used;\n \n bool backtrack(int i, int j,int k,string word, vector<vector<char>>& board){\n if(k==word.size()) return true;\n \n if(used.find(i*board[0].size()+j)!=used.end()) return false;\n \n \n \n ...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\n public:\n bool exist(vector<vector<char>>& board, string word) {\n map<char, vector<pair<int, int>>> m;\n\n for (int i = 0; i < board.size(); i++) {\n for (int j = 0; j < board[i].size(); j++) {\n if (m.count(board[i][j]) == 0) {\n m[board[i][j]] = vector<pair...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\nprivate:\n static const vector<vector<int>> dirs_;\npublic:\n bool dfs(vector<vector<char>>& board, string& word, vector<int> start, int i) {\n int x = start[0];\n int y = start[1];\n if(board[x][y] != word[i]) return false;\n if(board[x][y] == word[i] &&...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\nprivate:\n static const vector<vector<int>> dirs_;\npublic:\n bool dfs(vector<vector<char>>& board, string& word, vector<vector<bool>>& seen, vector<int> start, int i) {\n int x = start[0];\n int y = start[1];\n if(board[x][y] != word[i]) return false;\n ...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\n //Pruning: https://leetcode.com/problems/word-search/discuss/1908561/C%2B%2B%3A-How-to-prune-the-DFS-to-0ms\n \n bool solve(int idx, int x, int y, int m, int n, vector<vector<char>> &arr, string &word, vector<vector<int>> &vis)\n {\n if(i...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool solve(vector<vector<char>>&board,string word,int index,int i,int j){\n if(index>=word.size()){\n return true;\n }\n if(i<0 || j<0 || i>=board.size() || j>=board[0].size() || board[i][j]!=word[index]){\n return false;\n }\...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool exist(vector<vector<char>>& board, string word) {\n int rows = board.size();\n int cols = board[0].size();\n unordered_set<string> visited;\n\n auto dfs = [&](int r, int c, int k, auto& dfs) -> bool {\n if (k == word.length()) {\n ...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool exist(vector<vector<char>>& board, string word) {\n int rows = board.size();\n int cols = board[0].size();\n unordered_set<string> visited;\n\n auto dfs = [&](int r, int c, int k, auto& dfs) -> bool {\n if (k == word.length()) {\n ...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool exist(vector<vector<char>>& board, string word) {\n int rows = board.size();\n int cols = board[0].size();\n unordered_set<string> visited;\n\n auto dfs = [&](int r, int c, int k, auto& dfs) -> bool {\n if (k == word.length()) {\n ...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool exist(vector<vector<char>>& board, string word) {\n int rows = board.size();\n int cols = board[0].size();\n unordered_set<string> visited;\n\n auto dfs = [&](int r, int c, int k, auto& dfs) -> bool {\n if (k == word.length()) {\n ...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool exist(vector<vector<char>>& board, string word) {\n int rows = board.size();\n int cols = board[0].size();\n unordered_set<string> visited;\n\n auto dfs = [&](int r, int c, int k, auto& dfs) -> bool {\n if (k == word.length()) {\n ...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n\n struct Node\n {\n Node():child(128, nullptr){}\n vector<Node*> child; \n };\n \n Solution():dr{0, 0, -1, 1}, dc{1, -1, 0, 0}\n {\n root = new Node();\n }\n \n void build_trie(vector<vector<char>> &board, int r, int c, int len, N...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\n private: unordered_set<char> myset;\npublic:\n bool exist(vector<vector<char>>& board, string word) {\n const int m = board.size();\n const int n = board[0].size();\n vector<int> temp;\n for(int i = 0;i<m;i++){\n for(int j = 0;j<n;j++){\n ...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\nprivate:\n static const vector<vector<int>> dirs_;\npublic:\n bool dfs(vector<vector<char>>& board, string& word, stack<vector<int>>& s, vector<vector<bool>>& seen, vector<int> start, int i) {\n int x = start[0];\n int y = start[1];\n if(board[x][y] != word[i])...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n vector<vector<bool>> vis;\n bool helper(vector<pair<int, int>> list, vector<vector<char>>& board, string word, int ind){\n if(ind == word.size()){\n return true;\n }\n for(int i = 0; i < list.size(); i++){\n if(board[list[i].first...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n void printB(vector<vector<char>>& curr) {\n for (vector<char> v : curr) {\n for (char c : v) {\n cout << c;\n }\n cout << endl;\n }\n }\n bool solve(vector<vector<char>>& curr, int row, int col, int m, int n,...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\nprivate:\n vector<vector<bool>> visited;\n\npublic:\n bool exist(vector<vector<char>>& board, string word) {\n if (board.empty())\n return false;\n int m = board.size(), n = board[0].size();\n\n visited = vector<vector<bool>>(m, vector<bool>(n, false)...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\nprivate:\n vector<vector<bool>> visited;\n\npublic:\n bool exist(vector<vector<char>>& board, string word) {\n if (board.empty())\n return false;\n int m = board.size(), n = board[0].size();\n\n visited = vector<vector<bool>>(m, vector<bool>(n, false)...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\nprivate:\n vector<vector<bool>> visited;\n\npublic:\n bool exist(vector<vector<char>>& board, string word) {\n if (board.empty())\n return false;\n int m = board.size(), n = board[0].size();\n\n visited = vector<vector<bool>>(m, vector<bool>(n, false)...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\nprivate:\n class stack_entry {\n public:\n pair<int, int> loc;\n bool status;\n bool found_visited;\n\n stack_entry() = default;\n\n stack_entry(int i, int j) {\n loc = {i, j};\n status = false;\n ...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\nprivate:\n class stack_entry {\n public:\n pair<int, int> loc;\n bool status;\n bool found_visited;\n\n stack_entry() = default;\n\n stack_entry(int i, int j) {\n loc = {i, j};\n status = false;\n ...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n int index(int i, int j, int m) {\n return i * m + j;\n }\n bool busy(uint64_t mask, int i, int j, int m) {\n int idx = index(i, j, m);\n return (mask & (1ULL << idx)) > 0;\n }\n uint64_t set_bit(uint64_t mask, int i, int j, int m) {\n i...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n int index(int i, int j, int m) {\n return i * m + j;\n }\n bool busy(uint64_t mask, int i, int j, int m) {\n int idx = index(i, j, m);\n return (mask & (1ULL << idx)) > 0;\n }\n uint64_t set_bit(uint64_t mask, int i, int j, int m) {\n i...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n int index(int i, int j, int m) {\n return i * m + j;\n }\n bool busy(uint64_t mask, int i, int j, int m) {\n int idx = index(i, j, m);\n return (mask & (1ULL << idx)) > 0;\n }\n uint64_t set_bit(uint64_t mask, int i, int j, int m) {\n i...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool exist(vector<vector<char>>& board, string word) {\n unordered_map<char, int> freq;\n vector<int> starts;\n int n = board[0].size();\n // maintain freq of each character to be found\n for (auto& ch : word) {\n if (freq.find(ch...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool fun(int i,int j,string s1,string word,vector<vector<int>>&vis,vector<vector<char>>& board){\n if(s1==word||s1+board[i][j]==word)return true;\n if(s1.length()>=word.length())return false;\n vector<int>x1{0,0,1,-1},y1{1,-1,0,0};\n for(int k=0;k<...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool fun(int i,int j,string s1,string word,vector<vector<int>>&vis,vector<vector<char>>& board){\n if(s1==word||s1+board[i][j]==word)return true;\n if(s1.length()>=word.length())return false;\n vector<int>x1{0,0,1,-1},y1{1,-1,0,0};\n for(int k=0;k<...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> delta;\n bool exist(vector<vector<char>>& board, string word) {\n \n int row = board.size();\n int col = board[0].size();\n int n = word.size();\n if(n==0){\n return true;\n }\n if(n>row*col){\...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool solve(vector<vector<char>>& board, string& word, int pointer, int i, int j, int n, int m, vector<vector<bool>>& visited,vector<vector<int>>& dir) {\n if (pointer == word.size()) return true;\n if (i < 0 || i >= n || j < 0 || j >= m || board[i][j] != word[po...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool rec_func(int curr, int curc,int curi,string word,vector<vector<char>> &board,vector<vector<bool>> &vis,vector<vector<int>>& moves){\n if(board[curr][curc]!=word[curi]){\n return false;\n }\n if(curi==word.size()-1){\n return tru...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n\n\nvector<vector<char>> board;\nvector<vector<int>> moves = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};\nstring word;\n\n\nbool backtrack(int row, int col, unordered_map<string, bool> &visited, string current, int matchIdx) {\n\n if(word == current) {\n return true;\n }\n\n...
79
<p>Given an <code>m x n</code> grid of characters <code>board</code> and a string <code>word</code>, return <code>true</code> <em>if</em> <code>word</code> <em>exists in the grid</em>.</p> <p>The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically ne...
3
{ "code": "class Solution {\npublic:\n bool exist(vector<vector<char>>& board, string word) {\n \n int c1 = count(word.begin(), word.end(), word[0]);\n int c2 = count(word.begin(), word.end(), word.back());\n\n if (c1 > c2) {\n reverse(word.begin(), word.end());\n }\n\...