id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n int n = s.size();\n int m = p.size();\n if(n>0 && m>0 && s[n-1]!=p[m-1] && p[m-1]!='?' && p[m-1]!='*') return false;\n vector<vector<int>>dp(n, vector<int>(m, -1));\n return match(n-1, s, m-1, p, dp);\n ...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\n int dp[2100][2100];\n int n,m;\npublic:\n int rec(int i,int j,string& u,string& v){\n if(i==n&&j==m){\n return 1;\n }\n else if(i==n){\n for(int index=j;index<m;index++){\n if(v[index]!='*'){\n return 0...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\npublic:\n int solve(string& s, string& p, int i, int j, vector<vector<int>>& dp){\n if(i<0 && j<0) return 1;\n if(j==0 && p[0]=='*') return 1;\n if(i<0 || j<0) return 0;\n if(dp[i][j] != -1) return dp[i][j];\n\n if(s[i]==p[j] || p[j]=='?') return dp[i...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> history;\n long long base_s;\n long long base_p;\n\n bool solveIsMatch(const char* s, const char* p) {\n if (s[0] == '\\0' && p[0] == '\\0')\n return true;\n if (s[0] != '\\0' && p[0] == '\\0')\n return false;\n...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\n string removeConsecutiveStars(string& p)\n {\n if(p == \"\")\n return p;\n\n string res;\n res += p[0];\n for(int i=1; i<p.size(); i++)\n {\n if(p[i] == '*' && p[i] == p[i-1])\n continue;\n \n ...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\n string removeConsecutiveStars(string& p)\n {\n if(p == \"\")\n return p;\n\n string res;\n res += p[0];\n for(int i=1; i<p.size(); i++)\n {\n if(p[i] == '*' && p[i] == p[i-1])\n continue;\n \n ...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\npublic:\n bool recurse(string &s, string &p, int curs, int curp, vector<vector<int>>&dp){\n if(curs==s.size() && curp==p.size()){\n dp[curs][curp]=2;\n return true;\n }\n\n if(dp[curs][curp]!=-1){\n return (dp[curs][curp]==1)?false:...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\npublic:\n bool solve(int i, int j, string &s, string &t,vector<vector<int>> &dp){\n if(j == t.size()){\n return i == s.size();\n }\n if(dp[i][j]!=-1)return dp[i][j];\n bool match = (i < s.size() && (t[j]=='?' || (s[i]==t[j]) ) );\n if(t[j]=...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\npublic:\n bool find(string &a,int n,string &b,int m,vector<vector<int>> &dp)\n {\n if(n<0)\n {\n while(m>=0)\n {\n if(b[m--]!='*')\n return false;\n }\n return true;\n }\n if(m<...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n int n = s.size();\n int m = p.size();\n vector<int> dp(m + 1, 0);\n dp[0] = 1;\n for (int i = 0; i < n; i++) {\n vector<int> ndp(m + 1, 0);\n for (int j = 0; j < m; j++) {\n ...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\npublic:\n // int solve(string& s, string& p,int n,int m,vector<vector<int>>& dp){\n // if(n<0 && m<0) return true;\n // if(n<0 && m>=0){\n // while(m>=0){\n // if(p[m]!='*') return false;\n // m--;\n // }\n // ...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\npublic:\n// bool rec(int i, int j, string s, string p, vector<vector<int>> &dp) {\n// if(i==0 && j>0) {\n// //string is exhausted. Pattern must be all '*'s. \n// for(int k=0; k<j; k++){\n// if(p[k]!='*') return false;\n// }\n// return true;\...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\npublic:\n int n,m;\n vector<vector<int>> dp;\n bool solve(string &pattern,string &str,int i,int j){\n if((i>=n) && (j>=m)){\n return true;\n }\n if(i>=n){\n return false;\n }\n if(dp[i][min(j,m)]!=-1){\n return d...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\nprivate:\n bool solve(int i, int j, string& s, string& p, vector<vector<int>>& dp) {\n if(i < 0) {\n for(int k = 0; k <= j; k++) {\n if(p[k] != '*') return false;\n }\n return true;\n }\n if(j < 0) return false;\n ...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\npublic:\n\n int f(int i, int j, string &p, string &s, vector<vector<int>> &dp) {\n // Base cases\n if (i < 0 && j < 0) return 1; // Both strings exhausted -> match\n if (i < 0) return 0; // Pattern exhausted but string remains -> no match\n if (j < 0) { \n ...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\npublic:\n bool stars(string &p,int a){\n for(int i=0;i<=a;i++){\n if(p[i]!='*'){\n return 0;\n }\n }\n return 1;\n }\n \n int check(int i, int j, string &p, string &s,vector<vector<int>>&dp){\n if(i<0 && j<0){\n ...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\npublic:\n bool f(int i,int j,string& p,string& s,vector<vector<int>>&dp){\n if(i==0 && j==0)return true;\n if(i==0 && j>0)return false;\n if(j==0 && i>0){\n for(int u=0;u<i;u++){\n if (p[u]!='*')return false;\n }\n re...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\npublic:\n bool solve(int i, int j , string &s, string &t, vector<vector<int>> &dp){\n\n if(i<0 && j<0) return true; // both strings are exausted\n if(i<0 && j>=0) return false; //some comparisons are still left\n if(j<0 && i>=0) {\n for(int ii=0; ii<=i ...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\nprivate:\n int f(int i, int j, string &p, string &t, vector<vector<int>> &dp){\n if (i==0 && j==0) return 1;\n if (i==0 && j>0) return 0;\n if (j==0 && i>0){\n for(int ii=1; ii<=i; ii++){\n if (p[ii-1] != '*') return 0;\n }\n ...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\npublic:\n bool solve(string& s, string& p, int i, int j, vector<vector<int>>& dp) {\n // Base Cases\n if (i < 0 && j < 0) return true; // Both strings are fully matched\n if (i >= 0 && j < 0) return false; // Pattern exhausted but string still has characters\n ...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\npublic:\n // bool solve(int n1,int n2,string s,string p,vector<vector<int>>&dp){\n // if(n1<0 && n2<0){\n // return true;\n // }\n // if(n2<0){\n // return false;\n // }\n // if(n1<0){\n // for(int i=0;i<=n2;i++){\n ...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
2
{ "code": "class Solution {\npublic:\n bool solve(int i,int j,string &s,string &t,vector<vector<int>>&dp) {\n if (i<0 && j<0)\n return true;\n\n if (j<0)\n return false;\n\n if (i<0) {\n for (int k=0;k<=j;k++) {\n if (t[k]!='*')\n return f...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
3
{ "code": "class Solution {\npublic:\n bool solve(int i, int j, string& text, string& pattern, vector<vector<int>>& dp) {\n // BASE CASES\n if(i == 0 && j == 0) return true;\n if(i != 0 && j == 0) return false;\n if(i == 0 && j != 0) {\n for(int k = 0; k < j; k++) {\n ...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
3
{ "code": "class Solution {\npublic:\n bool fun(int index1, int index2, string& s, string& p, vector<vector<int>> &dp) {\n if (index1 < 0 && index2 < 0)\n return 1;\n if(index1<0 &&index2>=0)\n {\n for(int j=index2;j>=0;j--)\n {\n if(p[j]!='*')\n...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
3
{ "code": "class Solution {\npublic:\n bool solve(string s, string p, int i, int j){\n // Base case: both strings are exhausted, so they match\n if (i<0 && j<0) {\n return true;\n }\n // If pattern is exhausted but string is not, they don't match\n if (i>=0 && j<0) {\n...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
3
{ "code": "class Solution {\npublic:\n bool solve(string& s, string& p, int i, int j, vector<vector<int>>& dp){\n if(i==0 && j==0) return true;\n\n if(i>0 && j==0) return false;\n\n if(i==0 && j>0){\n for(int k=1; k<=j; k++){\n if(p[k-1] != '*') return false;\n ...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
3
{ "code": "class Solution {\npublic:\n bool isMatch(string s, string p) {\n //dp[i][j] means if pattern p[0:j] matches string s[0:i] \n vector<vector<int>> dp(s.size() + 1, vector<int>(p.size() + 1, 0));\n s = \"#\" + s;\n p = \"#\" + p;\n dp[0][0] = true;\n\n for(int j = ...
44
<p>Given an input string (<code>s</code>) and a pattern (<code>p</code>), implement wildcard pattern matching with support for <code>&#39;?&#39;</code> and <code>&#39;*&#39;</code> where:</p> <ul> <li><code>&#39;?&#39;</code> Matches any single character.</li> <li><code>&#39;*&#39;</code> Matches any sequence of cha...
3
{ "code": "class Solution {\n // Helper function for the recursive DP approach\n bool f(int i, int j, string &s, string &p, vector<vector<int>> &dp) {\n // Base case: if either index is negative\n if (i < 0 || j < 0) {\n // If one index is negative and the other is not, return false\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
0
{ "code": "int init = [] {\n cin.tie(nullptr)->sync_with_stdio(false);\n freopen(\"user.out\", \"w\", stdout);\n\n for (string s; getline(cin, s);) {\n int solution = 0;\n int farthest = 0;\n int index = 0;\n int end = 0;\n\n for (int i = 1, n = s.length(); i < n; ++i) {\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
0
{ "code": "int init = [] {\n cin.tie(nullptr)->sync_with_stdio(false);\n freopen(\"user.out\", \"w\", stdout);\n\n for (string s; getline(cin, s);) {\n int solution = 0;\n int farthest = 0;\n int index = 0;\n int end = 0;\n\n for (int i = 1, n = s.length(); i < n; ++i) {\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
0
{ "code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\nstatic const bool __boost = []() {\n\tcin.tie(nullptr);\n\tcout.tie(nullptr);\n\treturn std::ios_base::sync_with_stdio(false);\n\t}();\n\n\nconst size_t BUFFER_SIZE = 0x6fafffff;\nalignas(std::max_align_t) char b...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
0
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n int n = nums.size();\n if (n == 1) return 0;\n int jumps = 0;\n int current_end = 0;\n int farthest = 0;\n \n for (int i = 0; i < n - 1; i++) {\n farthest = max(farthest, i + nums[i]);\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
0
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n int maxi=0,n=nums.size();\n if(n<=1)return 0;\n int ans=0;\n \n int endindex=0;\n\n for(int i=0;i<n;i++){\n maxi=max(maxi,nums[i]+i);\n if(i==endindex){\n endindex=m...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
0
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n \n if( nums.size() == 1)\n return 0;\n\n int maxReachableId = 0;\n int stepCount = 0;\n int currentPos = 0;\n\n for (int i = 0; i < nums.size(); i++)\n {\n // Is last step\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
0
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n int ans=0,l=0,r=0;\n \n int n=nums.size();\n while(r<n-1){\n int maxi=0;\n \n for(int i=l; i<=r; i++){\n maxi=max(maxi,i+nums[i]);\n }\n l=r+1;\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
0
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) { \n int l=0;\n int r=0;\n int jumps =0;\n while(r<nums.size()-1)\n { int farthest=r;\n for(int index=l;index<=r;index++)\n {\n farthest =max (farthest, index + nums[index]);\...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
0
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n \n int sz = nums.size(), numJumps = 0, reach = 0, lastJumpPos = 0, i = 0;\n\n while(lastJumpPos < sz - 1) {\n\n reach = max(reach, i + nums[i]);\n \n if(lastJumpPos == i) {\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
0
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n int count = 0, farthest = 0, endOfCurrentJump = 0;\n \n for (int i = 0; i < nums.size() - 1; ++i) {\n farthest = max(farthest, i + nums[i]);\n \n // If we've reached the end of the current j...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
0
{ "code": "class Solution {\npublic:\n int jump(std::vector<int>& nums) {\n int n = nums.size();\n if (n == 1) {\n return 0;\n } \n \n int jumps = 0;\n int current_end = 0;\n int farthest = 0;\n \n for (int i = 0; i < n - 1; ++i) {\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
0
{ "code": "\nclass Solution {\npublic:\n\n int jump(vector<int>& nums) {\n\n for(int i = 1; i < nums.size(); i++)\n {\n nums[i] = max(nums[i] + i, nums[i-1]);\n }\n\n int ind = 0;\n int ans = 0;\n\n while(ind < nums.size() - 1)\n {\n ans++;\n ind = nums[ind];...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
2
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n if(nums.size()==1 || nums.size()==0)return 0;\n int cnt=1;\n int max_so_far=nums[0];\n int next_jump=nums[0];\n for(int i=1;i<nums.size();i++){\n if(i>max_so_far){\n cnt++;\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
2
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n if(nums.size()==1) return 0;\n int jump=0;\n int maxIdx = 0;\n int currIdx = 0;\n for(int i=0;i<nums.size();i++){\n maxIdx = max(maxIdx,i+nums[i]);\n if (i == currIdx) {\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
2
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n int size = static_cast<int>(nums.size());\n\n if(size == 1) {\n return 0;\n }\n \n // table[num_steps] is the index of the first element, for which the end is reachable with, or -1\n // if no...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
2
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n int n = nums.size();\n vector<int> dp(n, n);\n dp[n-1] = 0;\n int j = n-1;\n for(int i=n-2; i>=0; i--){\n int result = n;\n int bound = min(n-1, i+nums[i]);\n for(int k=bound; ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
2
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n vector<int> jumps(nums.size(), 10001);\n jumps[0] = 0;\n\n for (int i = 0; i < nums.size(); i++){\n for (int j = 1; j <= nums[i] && i+j < nums.size(); j++){\n if (jumps[i+j] > jumps[i] + 1) {\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
2
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n int n = nums.size();\n vector<int> dis(n, 1e4 + 1);\n dis[0] = 0;\n for (int i = 0; i < n; i++) {\n for (int j = i; j <= i + nums[i] && j < n; j++) {\n dis[j] = min(dis[j], dis[i] + 1);\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
2
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n static const int INF = 1000000;\n int DP[10000];\n DP[0] = 0;\n for(int ind = 1; ind < nums.size();++ind)\n {\n DP[ind] = INF;\n for(int k = 1; k <=1000; ++k)\n {\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
2
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n int n = nums.size();\n vector<int> dis(n, 1e4 + 1);\n dis[0] = 0;\n for (int i = 0; i < n; i++) {\n for (int j = i; j <= i + nums[i] && j < n; j++) {\n dis[j] = min(dis[j], dis[i] + 1);\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
2
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n int n = nums.size();\n vector<int> dis(n, 1e4 + 1);\n dis[0] = 0;\n for (int i = 0; i < n; i++) {\n for (int j = i; j <= i + nums[i] && j < n; j++) {\n dis[j] = min(dis[j], dis[i] + 1);\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
2
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n int n=nums.size();\n vector<int> dp(n,INT_MAX);\n dp[n-1]=0;\n for(int i=n-2; i>=0; i--){\n for(int j=1; j<=nums[i] && j+i<n; j++){\n if(dp[i+j]==INT_MAX) continue;\n dp[i]=mi...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
2
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n vector<int> min_jump(nums.size(), INT_MAX);\n min_jump[0] = 0;\n int max_sofar=0;\n for(int i=0;i<nums.size();i++)\n {\n max_sofar = max(max_sofar,i+nums[i]);\n for(int j=i+1;j<nums....
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
3
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n int n = nums.size();\n vector<int> dp(nums.size(), 0);\n dp[0] = 0;\n int ans = 1;\n for (int i = 0; i < n; i++){\n for (int j = 1; j <= nums[i]; j++){\n if (i + j < n && dp[i + j] ==...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
3
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n int n=nums.size();\n if(n==1)return 0;\n int minjumps=0;\n vector<int>a(n,0);\n a[0]=0;\n for(int i=0;i<n;i++){\n int j=i+1;\n while(j<n && j<=nums[i]+i){\n if(a[j]=...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
3
{ "code": "#include <vector>\n#include <queue>\n#include <tuple>\n\nclass Solution {\npublic:\n int jump(std::vector<int>& nums) {\n return BFS(nums);\n }\n\n\nprivate:\n\n int BFS(std::vector<int>& nums)\n {\n if (nums.size() == 1) return 0; // Already at the end\n\n int n = nums.si...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
3
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n int size = static_cast<int>(nums.size());\n \n // table[num_steps] is the index of the first element, for which the end is reachable with, or -1\n // if not set yet.\n // 'num_step' steps.\n std::vector...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
3
{ "code": "class Solution {\npublic:\n int dp[10001];\n int recursion(vector<int> &nums, int idx, int n){\n if(idx >= n-1){\n return 0;\n }\n if(dp[idx]!=-1){\n return dp[idx];\n }\n int min_steps = n; \n for(int i =1; i<=nums[idx]; i++ ){\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
3
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n int n = nums.size();\n vector<long> dp(n,1e9);\n dp[0]=0;\n for(int i= 1;i<=n-1;i++){\n for(int j = i;j>=0 and j>=i-1000;j--){\n if(nums[j]+j>=i) dp[i]= min(dp[j]+1,dp[i]);\n }\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
3
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n int maxi=0;\n vector<int> mx;\n int n=nums.size();\n if(n==1) return 0;\n int count=0;\n for(int i=0;i<n;i++){\n maxi=max(maxi,nums[i]+i);\n mx.push_back(maxi);\n }\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
3
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n int n = nums.size();\n vector<long> dp(n,1e9);\n dp[0]=0;\n for(int i= 1;i<=n-1;i++){\n for(int j = i;j>=0 and j>=i-1000;j--){\n if(nums[j]+j>=i) dp[i]= min(dp[j]+1,dp[i]);\n }\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
3
{ "code": "class Solution {\npublic:\n int jump1(vector<int> &nums, vector<int> &dp, int i){\n if(i>=nums.size()-1){\n return 0;\n }\n if(dp[i]!=-1){\n return dp[i];\n }\n int mini = nums.size()+1;\n for(int j=nums[i];j>0;j--){\n mini = min...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
3
{ "code": "class Solution {\npublic:\n int jump(vector<int>& nums) {\n int n = nums.size();\n if (n == 1) return 0; \n \n queue<pair<int, int>> q; \n vector<bool> visited(n, false);\n q.push({0, 0});\n visited[0] = true;\n \n while (!q.empty()) {\n ...
45
<p>You are given a <strong>0-indexed</strong> array of integers <code>nums</code> of length <code>n</code>. You are initially positioned at <code>nums[0]</code>.</p> <p>Each element <code>nums[i]</code> represents the maximum length of a forward jump from index <code>i</code>. In other words, if you are at <code>nums[...
3
{ "code": "class Solution {\npublic:\n // int dp_jump(vector<int>& memo, vector<int>& nums, int index){\n // if (index >= size(nums)-1){\n // return 0;\n // }\n // if (memo[index] != 1001) {\n // return memo[index];\n // }\n // for (int i = 1; i <= nums[inde...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> permute(vector<int>& nums) {\n int len = 1;\n for (int i = nums.size(); i > 1; i--) {\n len *= i;\n }\n vector<vector<int>> sols(len);\n for (int i = 0; i < len; i++) {\n sols[i] = nums;\n ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
0
{ "code": "class Solution\n{\npublic:\n vector<vector<int>> permute(vector<int>& nums)\n {\n int n = nums.size();\n int size = n;\n while (--n > 1) size *= n;\n n = nums.size();\n\n vector<vector<int>> res;\n res.resize(size);\n int r = 0;\n\n vector<int> ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
0
{ "code": "// a bit tricky but its very fast and time-efficient, doesn't even need optimizations it seems\nclass Solution\n{\npublic:\n vector<vector<int>> permute(vector<int>& nums)\n {\n // size calculation\n int n = nums.size();\n int size = n;\n while (--n > 1) size *= n;\n ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> permute(vector<int>& nums) {\n vector<vector<int>> ans;\n sort(nums.begin(), nums.end());\n do\n {\n ans.push_back(nums);\n }while(next_permutation(nums.begin(), nums.end()));\n return ans;\n }\n};", ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> permute(vector<int>& nums) {\n vector<vector<int>> result;\n permuteHelper(nums, 0, result);\n return result;\n}\n\n void permuteHelper(vector<int>& nums, int start, vector<vector<int>>& result) {\n if (start == nums.size()) {\n resul...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> permute(vector<int>& nums) {\n vector<vector<int>> ans;\n int size = nums.size();\n sort(nums.begin(), nums.end());\n do\n {\n ans.push_back(nums);\n }while(next_permutation(nums.begin(), nums.end()));\n...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
0
{ "code": "class Solution {\npublic:\n void backTrack(vector<int> &nums,int idx,int &n,vector<int> &t,vector<vector<int>> &ans){\n bool flag=true;\n for(int i=0;i<n;i++){\n if(t[i]==-11){\n flag=false;\n break;\n }\n }\n if(flag){\n ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
0
{ "code": "class Solution {\n private:\n void solve(vector<int>& nums,vector<vector<int>>& ans,int idx){\n if(idx>=nums.size()){\n ans.push_back(nums);\n return ;\n }\n for(int j=idx;j<nums.size();j++){\n swap(nums[idx],nums[j]);\n solve(nums,ans,...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> permute(vector<int>& nums) {\n vector<vector<int>> ans;\n int size = nums.size();\n sort(nums.begin(), nums.end());\n do\n {\n ans.push_back(nums);\n }while(next_permutation(nums.begin(), nums.end()));\n...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
0
{ "code": "class Solution {\npublic:\n\n void solve(vector<int> &a, int n, vector<vector<int>> &s,int idx){\n if(idx==n){\n s.push_back(a);\n return;\n }\n for(int i=idx;i<n;i++){\n swap(a[i],a[idx]);\n solve(a,n,s,idx+1);\n swap(a[idx],a[...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
0
{ "code": "class Solution {\nprivate:\n void recursivepermute(int index, vector < int > & nums, vector < vector < int >> & ans) {\n if (index == nums.size()) {\n ans.push_back(nums);\n return;\n }\n for (int i = index; i < nums.size(); i++) {\n swap(nums[index], nums[i]);\n ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
1
{ "code": "class Solution {\npublic:\nvoid permutations_function(int n, vector<int> &nums, vector<int> &ds, vector<int> &visited,\n vector<vector<int>> &ans)\n{\n // Base Condition\n if (ds.size() == n)\n {\n ans.push_back(ds);\n return;\n }\n\n for (int i = 0; i...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
1
{ "code": "class Solution {\npublic:\n void permutate(vector<vector<int>>& ans,vector<int>& perm,vector<int>& nums,int index){\n if(index == nums.size()){\n ans.push_back(perm);\n return;\n }\n for(int i =0;i<nums.size();i++){\n if(find(perm.begin(),perm.end(),...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> ans;\n void solve(int index, vector<int>&nums){\n int n=nums.size();\n if(index==n){\n ans.push_back(nums);\n return ;\n }\n\n for(int i=index; i<n;i++){\n swap(nums[index], nums[i]);\n ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
1
{ "code": "class Solution {\npublic:\n void reccu(int fr[], vector<int>& nums, vector<int>& ds, vector<vector<int>>&ans){\n if(ds.size()==nums.size()){\n ans.push_back(ds);\n return;\n }\n for(int i = 0; i<nums.size(); i++){\n if(!fr[i]){\n ds.pu...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> ans;\n int n;\n void helper(vector<int>&nums, int ind) {\n if(ind == n) {\n ans.push_back(nums);\n return;\n }\n\n for(int i=ind;i<n;i++) {\n //will swap the ind and an i index\n swap(n...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
1
{ "code": "class Solution {\npublic:\n vector<vector<int>> result;\n \n \n void permutation(vector<int> &nums,int i,int n){\n if(i==n){\n result.push_back(nums);\n return;\n }\n\n for(int j=i;j<=n;j++){\n swap( nums[i],nums[j]);\n permutation(...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\n\nprivate:\n vector<vector<int>> recursePermute(vector<int>& nums, int index){\n vector<vector<int>> response;\n if (index==nums.size()-1) {\n response.push_back(nums);\n return response;\n }\n vector<vector<int>> res = recursePermute(nums,index+1);\n ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\npublic:\nvoid backtrack(vector<vector<int>>& resultList, vector<int>& tempList, vector<int>& nums) {\n // If we match the length, it is a permutation\n if (tempList.size() == nums.size()) {\n resultList.push_back(tempList);\n return;\n }\n\n ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "\n class Solution {\npublic:\n void backtrack(vector<vector<int>> &ans,vector<int> &curr,vector<int>&nums){\n if(curr.size()==nums.size()){\n ans.push_back(curr);\n return;\n }\n for(auto num:nums){\n if(find(curr.begin(),curr.end(),num)==curr...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\n\nprivate:\n vector<vector<int>> recursePermute(vector<int>& nums, int index){\n vector<vector<int>> response;\n if (index==nums.size()-1) {\n response.push_back(nums);\n return response;\n }\n vector<vector<int>> res = recursePermute(nums,index+1);\n ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\n\n public:\n\n vector<vector<int>> permute(vector<int>& nums) {\n\n vector<vector<int>> ans;\n\n dfs(nums, vector<bool>(nums.size()), {}, ans);\n\n return ans;\n\n }\n\n private:\n\n void dfs(const vector<int>& nums, vector<bool>&& used, vector<int>&& path,\n\n vecto...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\nprivate:\n void swap(int & a, int & b){\n int t = a;\n a = b;\n b = t;\n }\n void permute(vector<vector<int>> & permutations, vector<int> nums, int l, int r){\n if(l >= r){ \n permutations.push_back(nums);\n return;\n }\n ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\npublic:\n void solve(int n, vector<int>& nums, vector<int> &output, vector<vector<int>> &ans, vector<bool> &vis) {\n if(output.size() == n) {\n ans.push_back(output);\n return;\n }\n\n for(int i = 0; i<n; i++) {\n if(!vis[i]) {\n ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\n\n public:\n\n vector<vector<int>> permute(vector<int>& nums) {\n\n vector<vector<int>> ans;\n\n dfs(nums, vector<bool>(nums.size()), {}, ans);\n\n return ans;\n\n }\n\n private:\n\n void dfs(const vector<int>& nums, vector<bool>&& used, vector<int>&& path,\n\n vecto...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\nprivate:\n void solve(vector<int>& nums, vector<int> output, int index, vector<vector<int>> &ans){\n //base case\n if(index>=nums.size()){\n ans.push_back(nums);\n return;\n }\n\n for(int i = index; i<nums.size(); i++){\n swa...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\n public:\n vector<vector<int>> permute(vector<int>& nums) {\n vector<vector<int>> ans;\n\n dfs(nums, vector<bool>(nums.size()), {}, ans);\n return ans;\n }\n\n private:\n void dfs(const vector<int>& nums, vector<bool>&& used, vector<int>&& path,\n vector<vector<int>>...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\n\n vector<vector<int>> helper(int ind, vector<int>& nums){\n if(ind >= nums.size()){\n return {{}};\n }\n\n vector<vector<int>> resPerms;\n vector<vector<int>> perms;\n\n perms = helper(ind + 1, nums);\n\n for(auto p: perms){\n ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\n\n public:\n\n vector<vector<int>> permute(vector<int>& nums) {\n\n vector<vector<int>> ans;\n\n dfs(nums, vector<bool>(nums.size()), {}, ans);\n\n return ans;\n\n }\n\n private:\n\n void dfs(const vector<int>& nums, vector<bool>&& used, vector<int>&& path,\n\n vecto...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\nprivate:\n\n void solve(vector<int> nums,vector<vector<int>>& ans,int index){\n int n=nums.size();\n if(index>=n){\n ans.push_back(nums);\n return;\n }\n for(int i=index;i<n;i++){\n swap(nums[index],nums[i]);\n solve(n...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\npublic:\n void solve(vector<vector<int>>& ans,vector<int>nums ,int index)\n {\n if(index>=nums.size())\n {\n ans.push_back(nums);\n return;\n }\n for(int i=index;i<nums.size();i++)\n {\n swap(nums[i],nums[index]);\n...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\n\npublic:\n\n vector<vector<int>> permute(vector<int>& nums) {\n\n int n = nums.size();\n\n vector<vector<int>> ans;\n\n vector<int> t(n);\n\n vector<bool> vis(n);\n\n function<void(int)> dfs = [&](int i) {\n\n if (i == n) {\n\n ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> permute(vector<int>& nums) {\n int n = nums.size();\n vector<vector<int>> ans;\n vector<int> t(n);\n vector<bool> vis(n);\n function<void(int)> dfs = [&](int i) {\n if (i == n) {\n ans.emplace_ba...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>> permute(vector<int>& nums) {\n vector<vector<int>> res;\n generate(res, nums, 0, nums.size());\n return res;\n }\n\n void generate(vector<vector<int>>& res, vector<int>& nums, int ind, int n){\n if(ind == nums.size()){\n ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\npublic:\n vector<vector<int>>ans;\n void getans(vector<int>&nums,vector<int>&temp, vector<bool>&visited){\n if(temp.size()==nums.size()){\n ans.push_back(temp);\n return ;\n }\n for(int i=0;i<nums.size();i++){\n if(visited[i]==0){\n ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\npublic:\n // void solve(int n, vector<int>& nums, vector<int> &output, vector<vector<int>> &ans, vector<bool> &vis) {\n // if(output.size() == n) {\n // ans.push_back(output);\n // return;\n // }\n\n // for(int i = 0; i<n; i++) {\n // ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
2
{ "code": "class Solution {\npublic:\n // void solve(int n, vector<int>& nums, vector<int> &output, vector<vector<int>> &ans, vector<bool> &vis) {\n // if(output.size() == n) {\n // ans.push_back(output);\n // return;\n // }\n\n // for(int i = 0; i<n; i++) {\n // ...
46
<p>Given an array <code>nums</code> of distinct integers, return <em>all the possible permutations</em>. You can return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre><strong>Input:</strong> nums = [1,2,3] <strong>Output:</strong> [[1,2,3],[1,3,2],[2...
3
{ "code": "class Solution {\npublic:\nvector<vector<int>> ans;\nvoid helper(vector<int>nums , int i){\n if(i==nums.size()){\n ans.push_back(nums);\n return;\n}\nfor(int j=i ; j<nums.size();j++){\nswap(nums[i],nums[j]);\nhelper(nums,i+1);\nswap(nums[i],nums[j]);\n}\nreturn;\n}\n vector<vector<int>>...