id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n void generateSubset(vector<int>& nums, int idx, int size, set<vector<int>> &res, vector<int>& ans){\n if(idx == size){\n res.insert(ans);\n return;\n }\n\n generateSubset(nums,idx+1,size,res,ans);\n\n ans.push_back(nums[idx]);...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\n void solver(vector<int>& nums, int i, vector<int>& v, set<vector<int>>& ans){\n if (i==nums.size()){\n sort(v.begin(), v.end());\n ans.insert(v);\n return;\n }\n solver(nums, i+1, v, ans);\n v.push_back(nums[i]);\n so...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "/*\n * @lc app=leetcode id=90 lang=cpp\n *\n * [90] Subsets II\n */\n\n// @lc code=start\nclass Solution\n{\npublic:\n vector<vector<int>> ans;\n void findsum(int i, vector<int> v, vector<int> &nums)\n {\n if(i>=nums.size())\n return;\n vector<int> temp = v;\n temp.push...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n set<vector<int>> ans;\n void backtracking(int cur_idx, vector<int> &nums, vector<int> &vec, vector<bool> &used) {\n if (cur_idx == nums.size()) {\n ans.insert(vec);\n return;\n }\n\n // if (cur_idx > 0 && nums[cur_idx] == nums[cur...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> subsetsWithDup(vector<int>& nums) {\n int n = nums.size();\n int subsetSize = pow(2,n);\n vector<vector<int>>result;\n\n set<map<int,int>>stt;\n\n for(int i=0; i<subsetSize; i++){\n vector<int>temp;\n ...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n void solve(int i, set<vector<int>>& s, vector<vector<int>>& ans, vector<int>&temp, vector<int>& nums){\n if(i==nums.size()){\n if(s.find(temp)==s.end()){\n s.insert(temp);\n ans.push_back(temp);\n }\n retur...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> vec;\n void solve(vector<int>& nums,int index, vector<int>& output,set<vector<int>>& ans){\n if(index >= nums.size()){\n if(ans.find(output) == ans.end()){\n ans.insert(output);\n vec.push_back(output);\n ...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n vector<int> ss;\n set<vector<int>> st;\n\n void rec(vector<int>& nums, int k) {\n if (k == nums.size()) {\n st.insert(ss);\n }\n else {\n rec(nums, k+1);\n ss[nums[k] + 10]++;\n rec(nums, k+1);\n ...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "set<vector<int>> ans;\nvoid generate(int i,int n, vector<int>& v,vector<int>& x){\n if (i>=n){\n sort(v.begin(),v.end());\n ans.emplace(v);\n return;\n }\n generate(i+1,n,v,x);\n v.push_back(x[i]);\n generate(i+1,n,v,x);\n v.erase(v.begin()+i);\n}\nclass Solution {\np...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n\n void helper(vector<int> nums, int i, vector<int> & current, vector<vector<int>> &result) {\n int n = nums.size();\n if(i==n) {\n result.push_back(current);\n return;\n }\n\n current.push_back(nums[i]);\n helper(nums, ...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n void solve(int index,vector<int>&nums,vector<vector<int>>&ans,vector<int>temp)\n {\n if(index>=nums.size())\n {\n \n ans.push_back(temp);\n return;\n }\n\n int i=index;\n\n while(i<nums.size()-1&&nums[i]==nums[i+1])...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n\n void subsetWithDuplicates(vector<int> &nums, int start, vector<int> currSet, vector<vector<int>> &res) {\n\n int n = nums.size();\n if (start == n) {\n res.push_back(currSet);\n return;\n }\n\n int i = start+1; int j;\n ...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n void getans(vector<int>&nums,int index, int n, vector<int>temp, vector<vector<int>>&ans){\n if(index==n){\n ans.push_back(temp);\n return;\n }\n //pick \n temp.push_back(nums[index]);\n getans(nums,index+1...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n void pmf(vector<int>& nums,int size,int i,vector<vector<int>>& vn,vector<int> v1)\n { \n if(i>=size)\n { vn.push_back(v1);\n return ;\n }\n\n \n v1.push_back(nums[i]);\n pmf(nums,size,i+1,vn,v1);\n v1.pop_back...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n\n void func(vector<int> &nums,int i,vector<int> &subs,set<vector<int>> &st,vector<vector<int>> &ans){\n if(i==nums.size()){\n vector<int> sorted_subs=subs;\n sort(sorted_subs.begin(),sorted_subs.end());\n if(st.find(sorted_subs)==st.end...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> ans;\n void fun(int i , int n, vector<int> &v, vector<int> tmp) {\n if(i>=n) {\n ans.push_back(tmp); return ;\n }\n int j = i+1 ;\n while(j<n && v[j] == v[j-1]) j++;\n fun(j,n,v,tmp);\n for(int k = i ...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> subsetsWithDup(vector<int>& nums) {\n sort(nums.begin(), nums.end());\n dfs(0, vector<int> (), nums);\n return ans;\n }\n\n void dfs(int i, vector<int> subset, vector<int>& nums){\n if(i == nums.size()){\n ans.p...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\n void solve(vector<int>&nums, int index, vector<int>output, vector<vector<int>> &ans){\n if(index>= nums.size()){\n if(find(ans.begin(),ans.end(),output)==ans.end())\n ans.push_back(output);\n return;\n }\n /*if(nums[index]== nums[index+1])\n i...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\nvoid solve(int ind,vector<int>&v,set<vector<int>>&ans,vector<int>nums){\n if(ind == nums.size()){\n ans.insert(v);\n return;\n }\n solve(ind+1,v,ans,nums);\n v.push_back(nums[ind]);\n solve(ind+1,v,ans,nums);\n v.pop_back();\n}\n vector<vector<...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n void helper(int i,int n,vector<int>& nums, vector<int> temp, vector<vector<int>>& ans){\n if(i==n){\n ans.push_back(temp);\n return;\n }\n temp.push_back(nums[i]);\n helper(i+1,n,nums,temp,ans);\n temp.pop_back();\n for(int j=i;j<n;j++){\n ...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n void helper(vector<int>& nums,vector<vector<int>>&ans,int i,vector<int> v){\n if(i==nums.size()){\n ans.push_back(v);\n return;\n }\n // if(i==0){\n // helper(nums,ans,i+1,v);\n // v.push_back(nums[i]);\n // help...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n\n void helper(vector<int> nums, set<vector<int>> &ans, vector<int> &temp, int n){\n if(n==nums.size()){\n ans.insert(temp);\n return;\n }\n temp.push_back(nums[n]);\n helper(nums, ans, temp, n+1);\n temp.pop_back();\n ...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n void rec(int i,vector<int>nums,set<vector<int>>& ans,vector<int>& temp,int n){\n if(i==n){\n // sort(temp.begin(),temp.end());\n ans.insert(temp);\n return;\n }\n temp.push_back(nums[i]);\n rec(i+1,nums,ans,temp,n);...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n void fn(int index, vector<int> current, vector<int>& nums, int n, set<vector<int>>& st) {\n if (index >= n) \n {\n st.insert(current); \n return;\n }\n fn(index + 1, current, nums, n, st);\n current.push_back(nums[index...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "#include <vector>\n#include <set>\n#include <algorithm> // For sorting\nusing namespace std;\n\nclass Solution {\npublic:\n void fn(int index, vector<int> current, vector<int>& nums, int n, set<vector<int>>& st) {\n if (index >= n) {\n st.insert(current); // Insert the current subset i...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n void solve(vector<int> &nums, vector<int> output, vector<vector<int>> &ans, int index) {\n if (index == nums.size()) {\n ans.push_back(output);\n return;\n }\n \n output.push_back(nums[index]);\n solve(nums, output, ans...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n\n void recur(vector<int>& nums,vector<int> temp,int index, vector<vector<int>>& ans){\n if(index == nums.size()){\n ans.push_back(temp);\n return;\n }\n //not pick\n recur(nums,temp,index+1,ans);\n //pick\n temp....
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n\n void solve(vector<int>&n, set<vector<int>>&ans, int ind, vector<int>temp){\n if(ind == n.size())\n {\n ans.insert(temp);\n return;\n }\n solve(n, ans, ind+1, temp);\n temp.push_back(n[ind]);\n solve(n, ans, ind...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n\n void helper(set<vector<int>> &res, vector<int> ans, vector<int> &nums, int i){\n if(i == nums.size()){\n res.insert(ans);\n return;\n }\n\n helper(res, ans, nums, i + 1);\n ans.push_back(nums[i]);\n helper(res,ans, nu...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n void solve(vector<int> &nums, int index, vector<int> temp, set<vector<int>> &s)\n {\n if(index >= nums.size())\n { \n sort(temp.begin(), temp.end());\n s.insert(temp);\n return ;\n }\n\n //include\n temp...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n\n void solve(vector<int>&n, set<vector<int>>&ans, int ind, vector<int>temp){\n if(ind == n.size())\n {\n sort(temp.begin(), temp.end());\n ans.insert(temp);\n return;\n }\n solve(n, ans, ind+1, temp);\n temp....
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n void solve(vector<int>& nums,set<vector<int>>&s,vector<int>temp,int ind){\n \n if(ind>=nums.size()){\n sort(temp.begin(),temp.end());\n s.insert(temp);\n return;\n }\n\n temp.push_back(nums[ind]);\n solve(num...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n void solve(int idx, vector<int>v, set<vector<int>>& res, vector<int>& nums){\n if(idx == nums.size()){\n sort(v.begin(),v.end());\n res.insert(v);\n return ;\n }\n v.push_back(nums[idx]);\n solve(idx+1,v,res,nums);\...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\nprivate:\nvoid x(vector<int>nums,vector<int>output,int index,vector<vector<int>>&ans){\n if(index>=nums.size())\n {\n auto it = find(ans.begin(), ans.end(), output);\n if(it==ans.end())\n ans.push_back(output);\n return;\n }\n x(nums,output,index...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> result;\n void solve(vector<int> nums, vector<int> ds, int index){\n if(index>=nums.size()){\n result.push_back(ds);\n return;\n }\n ds.push_back(nums[index]);\n solve(nums,ds,index+1);\n ds.pop_b...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\nprivate:\n void solve(vector<int>& ip, vector<int> op, set<vector<int>>& s)\n {\n if(ip.size() == 0)\n {\n sort(op.begin(),op.end());\n s.insert(op);\n return;\n }\n vector<int> ip1(ip.begin()+1,ip.end());\n solve(i...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n void helper_subset(vector<int>& nums, vector<vector<int>>& result, vector<bool>& inclusion, unordered_set<string>& dup, int idx) {\n if(idx == nums.size()) {\n vector<int> subset;\n string set_id = \"\";\n for(int i=0;i<nums.size();i++)...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n void helper_subset(vector<int>& nums, vector<vector<int>>& result, vector<bool>& inclusion, unordered_set<string>& dup, int idx) {\n if(idx == nums.size()) {\n vector<int> subset;\n string set_id = \"\";\n for(int i=0;i<nums.size();i++)...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n void helper_subset(vector<int>& nums, vector<vector<int>>& result, vector<bool>& inclusion, unordered_set<string>& dup, int idx) {\n if(idx == nums.size()) {\n vector<int> subset;\n string set_id = \"\";\n for(int i=0;i<nums.size();i++)...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n void solution(vector<int>v,vector<int>nums,int n,int idx,vector<vector<int>>& p){\n if(idx==n){\n sort(v.begin(),v.end());\n auto itr=find(p.begin(),p.end(),v);\n if(itr==p.end()){\n p.push_back(v);\n }\n \n return ;...
90
<p>Given an integer array <code>nums</code> that may contain duplicates, 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> <p>&nb...
3
{ "code": "class Solution {\npublic:\n set<vector<int>>st;\n vector<vector<int>>result;\n void solve(vector<int>nums,vector<int>& op){\n if(nums.size()==0){\n if(st.find(op)==st.end()){\n st.insert(op);\n result.push_back(op);\n }\n return...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
0
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n int c1 = 1, c2 = 0;\n for(int i = 0; i < s.size(); i++){\n int nc1, nc2;\n if(s[i] != '0') nc1 = c1 + c2;\n else nc1 = 0;\n\n if(i && (s[i - 1] < '2' || (s[i - 1] == '2' && s[i] <= '6')))...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
0
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n int n = s.size();\n int prev = 1;\n int prev2 = 0;\n for (int i = 0; i < s.size(); i++) {\n int cur = 0;\n int num = s[i] - '0';\n if (num != 0) {\n cur += prev;\n ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
0
{ "code": "class Solution\n{\npublic:\n int numDecodings(string s)\n {\n int n = s.length();\n int p = 1, pp = 0;\n for (int i = 0; i < n; i++) {\n int cur = 0;\n if (s[i] != '0') {\n cur += p;\n }\n if (i > 0 && s[i-1] != '0') {\n ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
0
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n if ( s.empty() || s[0] == '0' )\n {\n return 0;\n }\n if ( s.size() == 1 )\n {\n return 1;\n }\n \n int first = 1, second = 1;\n for ( int i = 1; i < s.size(); ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
0
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n int n = s.size();\n int f = 0, g = 1;\n for (int i = 1; i <= n; ++i) {\n int h = s[i - 1] != '0' ? g : 0;\n if (i > 1 && (s[i - 2] == '1' || (s[i - 2] == '2' && s[i - 1] <= '6'))) {\n h +...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
0
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n int n = s.size();\n if(s[0] - '0' == 0){\n return 0;\n }\n vector<int> dp(n+2 , 0);\n dp[0] =1;\n \n for(int i = 0 ; i< n ; i++){\n \n if(s[i] != '0'){ \n ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
0
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n\n int n = s.size();\n if(s[0] - '0' == 0){\n return 0;\n }\n vector<int> dp(n+2 , 0);\n dp[0] =1;\n \n for(int i = 0 ; i< n ; i++){\n \n if(s[i] != '0'){ \n ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
0
{ "code": "class Solution {\n int dp[101];\n int n;\n int fun(string &s, int i){\n if(i == n) return 1;\n if(s[i] == '0') return 0;\n if(dp[i] != -1) return dp[i];\n\n int notTake = fun(s, i+1);\n int take = 0;\n if(i+1 < n && (s[i] == '1' || (s[i] == '2' && s[i+1] <...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
0
{ "code": "class Solution {\n int dp[101];\n int n;\n int fun(string &s, int i){\n if(i == n) return 1;\n if(s[i] == '0') return 0;\n if(dp[i] != -1) return dp[i];\n\n int notTake = fun(s, i+1);\n int take = 0;\n if(i+1 < n && (s[i] == '1' || (s[i] == '2' && s[i+1] <...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
0
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n if(s[0]=='0'){\n return 0;\n }\n int n = s.size();\n vector<int> dp(n+2, 0);\n dp[0] =1;\n for(int i =0; i<n;i++){\n if(s[i]!='0'){\n dp[i+1] += dp[i];\n ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
1
{ "code": "class Solution {\n int solve(string s, int index) {\n if (s[index] == '0') {\n return 0;\n }\n if (index == s.size()) {\n return 1;\n }\n\n int cnt = solve(s, index+1);\n if (index + 1 < s.size() && (s[index] == '1' || (s[index] == '2' && s...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
1
{ "code": "class Solution {\n int solve(string s, int index) {\n if (s[index] == '0') {\n return 0;\n }\n if (index == s.size()) {\n return 1;\n }\n\n int cnt = solve(s, index+1);\n if (index + 1 < s.size() && (s[index] == '1' || (s[index] == '2' && s...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
1
{ "code": "class Solution {\npublic:\n int dp[105];\n int f(int i, string& s)\n {\n if(i>=s.length())return 1;\n if(dp[i]!=-1)return dp[i];\n int ans=0;\n int op=s[i]-'0';\n int op2=0;\n if(i<s.length()-1)\n {\n op2= op*10+ s[i+1]-'0';\n }\n ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
1
{ "code": "class Solution {\n int dp[101];\n int n;\n int fun(string &s, int i){\n if(i == n) return 1;\n if(s[i] == '0') return 0;\n if(dp[i] != -1) return dp[i];\n\n int notTake = fun(s, i+1);\n int take = 0;\n if(i+1 < n && (s[i] == '1' || (s[i] == '2' && s[i+1] <...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
1
{ "code": "class Solution {\npublic:\n int numDecodings(std::string s) {\n if (s.empty() || s[0] == '0') {\n return 0;\n }\n\n int n = s.length();\n std::vector<int> dp(n + 1, 0);\n dp[0] = 1;\n dp[1] = 1;\n\n for (int i = 2; i <= n; ++i) {\n i...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
1
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n if (s[0] == '0') return 0; //edge case: no valid decode\n\n int prev = 1;\n int curr = 1;\n\n for (int i = 1; i < s.size(); i++) {\n int temp = 0;\n int n = stoi(s.substr(i-1, 2));\n i...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n if(s.empty() || s[0] == '0'){\n return 0;\n }\n int slen=s.length();\n std::vector<int> dp(slen+1,0);\n dp[0]=1;\n dp[1]=1;\n\n for(int i=2;i<=slen;i++){\n int oneDigit = s[i...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n bool isValid(string s){\n int num = std::stoi(s);\n if(num >=10 && num<=26) return true;\n else return false;\n }\n int numDecodings(string s) {\n int n = (int) s.size();\n if(s[0] == '0') return 0;\n if(n == 1) return 1;\n ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n int n = s.size();\n if (s[0] == '0') return 0;\n \n vector<int> dp(n + 1, 0);\n dp[0] = 1; \n dp[1] = (s[0] != '0') ? 1 : 0;\n\n for (int i = 2; i <= n; i++) {\n if (s[i - 1] != '0') {\...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n int numDecodings(std::string s) {\n if (s.empty() || s[0] == '0') {\n return 0;\n }\n\n int n = s.length();\n std::vector<int> dp(n + 1, 0);\n dp[0] = 1;\n dp[1] = 1;\n\n for (int i = 2; i <= n; ++i) {\n i...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n if(s.empty()||s[0]=='0'){\n return 0;\n }\n int n=s.size();\n vector<int> dp(n+1,0);\n dp[0]=1;\n dp[1]=1;\n for(int i=2;i<=n;i++){\n if(s[i-1]>='1'&&s[i-1]<='9'){\n ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n \n if(s.empty() || s[0] == '0')\n {\n return 0;\n }\n\n int n = s.length();\n\n vector<int> dp(n+1,0 );\n dp[0] = 1;\n dp[1] = 1;\n \n for(int i=2; i<=n ; i++)\n {\n if(s[i-1]...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n bool check(char x, char y){\n if(x >= '1' && x <= '2' && y >= '0' && y <= '6') return 1;\n return 0;\n}\n\nint numDecodings(string s) {\n if (s.empty() || s[0] == '0') {\n return 0;\n }\n\n int n = s.size();\n vector<int> dp(n + 1, 0);\n dp[0] = 1;...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n\n int n=s.size();\n\n if (n == 0 || s[0] == '0') return 0;\n\n vector <int> dp (n+1,0);\n dp[0]=1; \n\n if (s[0]!='0') dp[1]=1;\n\n for(int i=2; i<=n; i++){\n\n // single digit decoding\n if (s[i-1]!='0') dp[i]+=d...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n vector<int> dp(s.length() + 1);\n if(s[0] == '0') {\n return 0;\n }\n dp[0] = 1;\n dp[1] = 1;\n for(int i = 2; i <= s.length(); i++) {\n if(s[i - 1] != '0') {\n dp[i]...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "//Recursive DP\nclass Solution {\npublic:\n // Memoization table to store results of subproblems\n unordered_map<int, int> dp;\n\n int dfs(const string& s, int i) {\n if (dp.find(i) != dp.end()) return dp[i]; // Return cached result if found\n if (i == s.size()) return 1; // Reached ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n int step = 0;\n void tot(string &s , int idx){\n if(idx>=s.size()){\n step++;\n return;\n }\n if(s[idx]!='0'){\n // take one\n tot(s,idx+1);\n\n // take 2\n if(idx+1<s.size()){\n ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\n vector<int> memo;\n string s;\n int N;\npublic:\n int numDecodings(string str) {\n \n /**\n 2 2 6 \n\n dp(0) = 1\n dp(1) = 2\n dp(2) = 1 + 2 = 3\n\n For each i, dp(i) is how many ways to break at i plus ways...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\n map<size_t, int> m_cache;\npublic:\n int _numDecodings(const char* s, size_t len) {\n //cout << \"s: \" << s << endl;\n if (len == 0) return 1;\n if (*s == '0') return 0;\n if (len == 1) return 1;\n\n if (m_cache.count(len)) return m_cache[len]...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n string a;\n int n;\n int dp[110];\n int rec(int ind){\n if(ind == n)return 1;\n if(a[ind] == '0')return 0;\n\n if(dp[ind]!=-1)return dp[ind];\n\n int cnt = rec(ind+1);\n if((ind+1)<n && (stoi(a.substr(ind,2))<=26)){\n cnt...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n int n =s.size();\n if(n==0 || s[0]=='0') return 0;\n\n vector<int>dp(n+1,0);\n\n dp[0] = 1;\n if(s[1] != '0'){\n dp[1] = 1;\n }\n else{\n dp[1] = 0;\n }\n\n fo...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n if(s[0] == '0'){\n return 0;\n }\n int n = s.size();\n vector<int> dp(n + 1);\n dp[0] = 1;\n dp[1] = 1;\n\n for(int i = 2; i <= n; i++){\n int ones = stoi(s.substr(i - 1, 1))...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n if(s[0]=='0')return 0;\n        vector<int>dp(s.length()+1);\n        dp[0] = 1;\n        dp[1] = 1;\n        \n        for(int i=2;i<=s.length();i++){\n            int one = stoi(s.substr(i-1,1));\n            int two = stoi(s.substr(i-2...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n if(s[0]=='0') return 0 ;\n int n = s.size() ; \n\n vector<int> dp( n+1, 0 ) ; \n dp[0]=1; \n dp[1]=1 ;\n\n for (int i = 2 ; i <=n ;i++){\n int one = stoi( s.substr(i-1 , 1 ) ) ; \n ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n if(s[0] == '0') return 0;\n \n int n = s.length();\n vector<int> dp(n+1);\n dp[0] = 1;\n dp[1] = 1;\n for(int i=2; i<=n; i++){\n int ones = stoi(s.substr(i-1,1));\n if(ones>=...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n int numDecodings(string s) {\n if(s[0] == '0'){\n return 0;\n }\n\n int n = s.size();\n\n vector<int> dp(n + 1);\n dp[0] = 1;\n dp[1] = 1;\n\n for(int i = 2; i <= n; i++){\n int ones = stoi(s.substr(i - 1,...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n\n map<int, int> mem;\n\n int recurse(int index, string& str)\n {\n // if substring already seen, directly fetch the value\n if(mem.find(index) != mem.end())\n {\n return mem[index];\n }\n\n // reached end of string, return 1...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
2
{ "code": "class Solution {\npublic:\n map<int, int> memo;\n\n int recursiveWithMemo(int index, string& str) {\n // Have we already seen this substring?\n if (memo.find(index) != memo.end()) {\n return memo[index];\n }\n\n // If you reach the end of the string\n // ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n\n unordered_map<int, int> dict;\n\n void solve(string& s, int index, int& counter) {\n if (index == s.size() || (s[index] != '0' && index + 1 == s.size())) {\n counter++;\n return;\n }\n\n if (dict.count(index)) {\n cou...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n vector<int> memo = {};\n int numDecodings(string s) {\n /*\n a letter is either a single number or a double number\n a single number is trivial\n a double number must have the first number = 1 or 2\n if the...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\nint n;\nint dp[105];\nmap<int,char>mp;\nint f(int ind,string &s)\n{\n if(s[ind]=='0')return 0;\n\n if(ind>=n-1)return 1;\nif(dp[ind]!=-1)return dp[ind];\nint c=0;\nstring k=\"\";\n for(int i=ind;i<n;i++){\nk+=s[i];\nif(k.size()>2)break;\nif(mp.find(stoi(k))!=mp.end()){...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\n\npublic:\n\nint n;\n\nint dp[105];\n\nmap<int,char>mp;\n\nint f(int ind,string &s)\n\n{\n\n if(s[ind]=='0')return 0;\n\n if(ind>=n-1)return 1;\n\nif(dp[ind]!=-1)return dp[ind];\n\nint c=0;\n\nstring k=\"\";\n\n for(int i=ind;i<n;i++){\n\nk+=s[i];\n\nif(k.size()>2)break;\n\nif(...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\nint n;\nint dp[105];\nmap<int,char>mp;\nint f(int ind,string &s)\n{\n if(s[ind]=='0')return 0;\n\n if(ind>=n-1)return 1;\nif(dp[ind]!=-1)return dp[ind];\nint c=0;\nstring k=\"\";\n for(int i=ind;i<n;i++){\nk+=s[i];\nif(k.size()>2)break;\nif(mp.find(stoi(k))!=mp.end()){...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\nint n;\nint dp[105];\nmap<int,char>mp;\nint f(int ind,string &s)\n{\n if(s[ind]=='0')return 0;\n\n if(ind>=n-1)return 1;\nif(dp[ind]!=-1)return dp[ind];\nint c=0;\nstring k=\"\";\n for(int i=ind;i<n;i++){\nk+=s[i];\nif(k.size()>2)break;\nif(mp.find(stoi(k))!=mp.end()){...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\nint n;\nint dp[105];\nmap<int,char>mp;\nint f(int ind,string &s)\n{\n if(s[ind]=='0')return 0;\n\n if(ind>=n-1)return 1;\nif(dp[ind]!=-1)return dp[ind];\nint c=0;\nstring k=\"\";\n for(int i=ind;i<n;i++){\nk+=s[i];\nif(k.size()>2)break;\nif(mp.find(stoi(k))!=mp.end()){...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n int f(string s,int i,vector<int>&dp){\n if(i==s.size()) return 1;\n if(s[i]=='0') return 0;\n if(dp[i]!=-1) return dp[i];\n\n\n int count=f(s,i+1,dp);\n if(i+1<s.size()){\n int num=(s[i]-'0')*10+(s[i+1]-'0')*1;\n if(num>=10 && num<=26){\n ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\nint find(int ind,int n,string s,vector<int>&dp){\n if(ind >= n) return 1;\n if(dp[ind]!=-1) return dp[ind];\n int ones = 0, twos = 0;\n if(s[ind] > '0')\n ones = find(ind+1,n,s,dp);\n\n if(ind+1<n && (10*(s[ind] - '0') + (s[ind+1] - '0'))>=10 && (10*(s[ind] - '0...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n vector<int> mem;\nint decodings(string s,int i,int n){\n if(mem[i]>-1) return mem[i];\n if(i==n){\n return mem[i]=1;\n }\nif(s[i]=='0')return mem[i]=0;\nint result=decodings(s,i+1,n);\n// if(s[i]=='1')\nif(i+1<n)\n{if(s[i]=='1'||s[i]=='2' &&s[i+1]<='6'){\n ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n vector<int> dp;\n int bfs(int curr, string &s){\n if(s[curr] == '0') return 0;\n \n int n = s.size();\n if(curr >= n){\n return 1;\n }\n if(dp[curr] != -1) return dp[curr];\n string s1 = \"34\";\n if(curr<=...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n\n int decoded(int i, string s, vector<int> &dp)\n {\n if(s[i] == '0')\n return 0;\n if(i == s.size())\n {\n return 1;\n }\n if(dp[i] != -1)\n {\n return dp[i];\n }\n int one = decoded(i+1, s, dp)...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n int dp[102];\n int solve(int i,string s){\n if(i>=s.size())return 1;\n if(dp[i]!=-1)return dp[i];\n int ans=0;\n //choice 1 take 1 element\n if(s[i]!='0')ans+=solve(i+1,s);\n //take 2 element\n if(i+1<s.size() && (s[i]=='1' ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\nbool valid(string st){\n if(st[0]=='0')return 0;\n if(st.length()>2)return 0;\n int x=stoi(st);\n return x>=1 && x<=26;\n}\nint fun(string& s, int n,int i, vector<int>&dp){\n if(i>n)return 0;\n if(i==n){\n return 1;}\n if(dp[i]!=-1)return dp[i];\n int ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n int solve(int ind,string s,vector<int>&dp){\n if(ind<0) return 1;\n\n if(dp[ind]!=-1) return dp[ind];\n dp[ind]=0;\n if(s[ind]!='0') dp[ind] += solve(ind-1,s,dp);\n\n if(ind>=1 && s[ind-1]!='0' && ((s[ind-1]=='2' && s[ind]<='6') || (s[ind-1]...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n int solve(string s, int index, vector<int>& dp){\n if(index >= s.size()){\n return 1;\n }\n if(dp[index]!=-1){\n return dp[index];\n }\n if(s[index] != '0'){\n int ones = solve(s, index+1,dp);\n in...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n \n int solve(string &s, int i, int curr,unordered_map<int,unordered_map<int,int>> &dp) {\n if(i == s.length()) {\n if(curr > 0 && curr <= 26) {\n return 1;\n }\n return 0;\n }\n \n if (dp[i].find(c...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\n int numberOfResult( string s, int startIndex, vector<int> &cache){\n cout<<\"index \"<<startIndex<<endl;\n // base \n if (s[startIndex] == '0')\n return 0;\n\n if (startIndex >= s.length()-1){\n cout<<\"return 1\"<<endl;\n ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n int dp[101][27];\n int helper(string &s,int i,string prev)\n {\n if(i==s.length()) return 1;\n int p=0;\n if(prev!=\"\") p=stoi(prev);\n if(dp[i][p]!=-1) return dp[i][p]; \n int alone=0,combine=0;\n if(i>0 and s[i]!='0') alone=h...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\n int numberOfResult( string s, int startIndex, vector<int> &cache){\n cout<<\"index \"<<startIndex<<endl;\n // base \n if (s[startIndex] == '0')\n return 0;\n\n if (startIndex >= s.length()-1){\n cout<<\"return 1\"<<endl;\n ...
91
<p>You have intercepted a secret message encoded as a string of numbers. The message is <strong>decoded</strong> via the following mapping:</p> <p><code>&quot;1&quot; -&gt; &#39;A&#39;<br /> &quot;2&quot; -&gt; &#39;B&#39;<br /> ...<br /> &quot;25&quot; -&gt; &#39;Y&#39;<br /> &quot;26&quot; -&gt; &#39;Z&#39;</code></...
3
{ "code": "class Solution {\npublic:\n\n int f(string s, int n, int i, vector<int>&dp){\n if(i>=n){\n return 1;\n }\n if(s[i]=='0'){\n return 0;\n }\n if(dp[i]!=-1){\n return dp[i];\n }\n int ways = 0;\n ways += f(s,n,i+1,dp);...