id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\n // long long table[1002][1002];\n /*int calc(string &s, string &t, int i, int j){\n if(j==t.length()){\n return 1;\n }\n if( i>=s.length() ){\n return 0;\n }\n if(table[i][j]!=-1){\n return table[i][j];\n }... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>>dp;\n int f(string&s,string&t,int i,int j){\n if(i>=s.size()&&j>=t.size())return 1;\n if(j>=t.size()&&i<s.size())return 1;\n if(i>=s.size()&&j<t.size())return 0;\n if(dp[i][j]!=-1)return dp[i][j];\n if(s[i]==t[j]){\n ... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n\n int f(int i, int j, string &s, string &t, vector<vector<int>> &dp)\n {\n int n = s.size(), m = t.size();\n if(j == m) return 1;\n if(i == n) return 0;\n if(dp[i][j] != -1) return dp[i][j];\n\n int ans = f(i + 1, j, s, t, dp);\n i... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\nvector<vector<int>>dp;//as both index is changing only\n//traditional take and not_take ka hi problem hai\n//isme basically hame na s[i]==t[i] tbhi na isko lekr age bdhnge\nint helper(int s_index,int t_index,string &s,string &t)\n{\n if(t_index>=t.size()) return 1;//ye tbhi hi... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\nvector<vector<int>>dp;//as both index is changing only\n//traditional take and not_take ka hi problem hai\n//isme basically hame na s[i]==t[i] tbhi na isko lekr age bdhnge\nint helper(int s_index,int t_index,string &s,string &t)\n{\n if(t_index>=t.size()) return 1;//ye tbhi hi... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\n // long long table[1002][1002];\n /*int calc(string &s, string &t, int i, int j){\n if(j==t.length()){\n return 1;\n }\n if( i>=s.length() ){\n return 0;\n }\n if(table[i][j]!=-1){\n return table[i][j];\n }... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int numDistinct(string s, string t) {\n vector<vector<unsigned long long>> dp(1001, vector<unsigned long long>(1001, 0));\n for(int i = 0; i < s.length(); i++) {\n dp[0][i] = 1;\n }\n\n for(int i = 1; i <= t.length(); i++) {\n ... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int numDistinct(string s, string t) {\n return dp(s, t, 0, 0);\n }\n\n int dp(string s, string t, int i, int j) {\n if(j == t.length()) return 1;\n if(s.length() - i < t.length() - j) return 0;\n if(memo.contains(pair{i, j})) return memo[pair... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int getDistSubs(int nIndex, int nSize, int nOffset, string& sBase, string& sTarget, string sCurrent, map<string, map<int,int>>&dp) {\n\t\tif (nSize == nIndex) {\n\t\t\tif (0 == sCurrent.compare(sTarget)) {\n\t\t\t\treturn dp[sCurrent][nOffset] = 1;\n\t\t\t}\n\t\t}\n\t\tmap<st... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int ans = 0;\n int dp[1009][1009];\n int dfs(int p, int q, string s, string t){\n if(dp[p][q] != -1) return dp[p][q];\n if(s.length()-p < t.length()-q) return 0;\n int sum = 0;\n if(q == t.length()) return 1;\n for(int i = p; i < s.len... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\n vector<vector<int>> dp;\n\npublic:\n int numDistinct(string s, string t) {\n dp.assign(1001, vector<int> (1001, -1));\n return count(s, t);\n }\n int count(string s, string t) {\n int i = s.size(), j = t.size();\n if(j == 0) return 1;\n if(i... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n\n int dp[1001][1001];\n int solve(string s , string t , int index1 , int index2)\n {\n if(index2 >= t.size())\n {\n return 1;\n }\n else if(index1 >= s.size())\n {\n return 0;\n }\n\n if(dp[index1][i... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\n int util(string s, string t, int si, int ti) {\n if(ti == t.size()) {\n return 1;\n }\n if(si >= s.size()) {\n return 0;\n }\n if(dp[si][ti] != -1) {\n return dp[si][ti];\n }\n int ans = 0;\n if(s[si] == t[ti]) {\n ans += util(s, t, si+1, ti+1... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int dp[1001][1001];\n int func(int i,int j,string s, string t){\n int n=s.length(),m=t.length();\n if(j==m)return 1;\n else if(i==n)return 0;\n if(dp[i][j]!=-1)return dp[i][j];\n int x=0,y=0;\n if(s[i]==t[j]){\n x=func(i... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int dp[1001][1001];\n int solve(int i,int j,string s,string t){\n if(j==t.size())return 1;\n if(i>=s.size())return 0;\n if(dp[i][j]!=-1)return dp[i][j];\n int take=0,ntake=0;\n if(s[i]==t[j]){\n take = solve(i+1,j+1,s,t);\n ... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n\n int dp[1005][1005];\n\n int find(int s_index,int t_index,string s, string t){\n\n if(t_index == t.size()) return 1;\n if(s_index == s.size()) return 0;\n\n if(dp[s_index][t_index] != -1) return dp[s_index][t_index];\n int count = 0;\n\n ... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int cnt; \n int dp[1003][1003];\n int get(string s, string t, int i, int j){\n if(j>t.size()){\n return 1;\n }\n\n if(i>s.size()){\n return 0;\n }\n if(dp[i][j] != -1){\n return dp[i][j];\n }\n\n ... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int dp[1002][1002];\n //i => s and j => t\n int f(int i, int j, string s, string t)\n {\n if(j < 0) return 1;\n if(i < 0) return 0;\n if(dp[i][j] != -1) return dp[i][j];\n int take = 0, nottake = 0;\n if(s[i] == t[j]) take = f(i - 1... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\nint dp[1002][1002];\n int fun(int ind1,int ind2,string s,string t){\n if(ind2<0) return 1;\n if(ind1<0) return 0;\n\n\n if(dp[ind1][ind2]!=-1) return dp[ind1][ind2];\n int ans=0;\n if(s[ind1]==t[ind2]){\n ans+=fun(ind1-1,i... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int Solve(string &s,string t,int i,int j,vector<vector<int>>&dp){\n if(j==t.size()){\n return 1;\n }\n if(i==s.size()){//already handles j==t.size() from above,so no need to handle seperately\n return 0;\n }\n if(dp[i][... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int dp[1001][1001];\n int mod=INT_MAX;\n int solve(string s,string t,int n,int m){\n if(m==0) return 1;\n if(n==0) return 0;\n if(dp[n][m]!=-1) return dp[n][m];\n int sum=0;\n if(s[n-1]==t[m-1]){\n sum=(sum%mod+solve(s,t,n-1... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int Solve(string &s,string t,int i,int j,vector<vector<int>>&dp){\n if(j==t.size()){\n return 1;\n }\n if(i==s.size()){//already handles j==t.size() from above,so no need to handle seperately\n return 0;\n }\n if(dp[i][... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\nint dp[1001][1001];\nint func(int i1, int i2, string s1 , string s2){\n if(i2<0)return 1;\n if(i1<0)return 0;\n if(dp[i1][i2]!=-1)return dp[i1][i2];\n int ways=0;\n if(s1[i1]==s2[i2]){ways= func(i1-1, i2-1, s1, s2);}\n ways+= func(i1-1, i2, s1, s2);\n return ... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int helper(string s, string t, int i, int j, vector<vector<int>>&dp) {\n int N = s.size(), M = t.size();\n if(j >= M) {\n if(j == M) {\n return 1;\n }\n return 0;\n }\n if(i >= N) {\n retur... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\nprivate:\n int solve(int i,int j,string s, string t,vector<vector<int>> &dp){\n if(j<0) return 1;\n if(i<0) return 0;\n\n if(dp[i][j]!=-1) return dp[i][j];\n\n int first=0,second=0;\n\n if(s[i]==t[j]){\n first = solve(i-1,j-1,s,t,dp);\n ... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> dp;\n int solve(string& s, string t, int i, int j) {\n if (j >= t.size()) { \n return 1;\n }\n\n if (i >= s.size()) {\n return 0;\n }\n\n if (dp[i][j] != -1) return dp[i][j];\n \n in... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\n vector<vector<int>> distinctSubsequenceCountCache;\n\npublic:\n int numDistinct(string s, string t) {\n distinctSubsequenceCountCache =\n vector<vector<int>>(s.size(), vector<int>(t.size(), -1));\n return getDistinctSubsequenceCount(s, 0, t, 0);\n }\n\n ... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int result = 0;\n unordered_map<char, vector<int>> c_2_idx;\n vector<vector<int>> memo;\n int numDistinct(string s, string t) {\n for(int i = 0; i < s.length(); i++){\n c_2_idx[s[i]].push_back(i);\n }\n memo = vector<vector<int>>(t.len... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\n vector<vector<int>>distinctSubsequenceCountCache;\npublic:\n int numDistinct(string s, string t) {\n this->distinctSubsequenceCountCache = vector<vector<int>>(s.size(), vector<int>(t.size(), -1));\n return getDistinctSubsequence(s, 0, t, 0);\n }\n\n int getDisti... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int numDistinct(string s, string t) {\n if(s.size()<t.size())return 0;\n vector<vector<int>> mem(s.size(),vector<int>(t.size(),-1));\n return solve(s,t,0,0,mem);\n }\n int solve(string s, string t, int s_begin, int t_begin, vector<vector<int>>& mem)... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int numDistinct(string s, string t) {\n if(s.size()<t.size())return 0;\n vector<vector<int>> mem(s.size(),vector<int>(t.size(),-1));\n return solve(s,t,0,0,mem);\n }\n int solve(string s, string t, int s_begin, int t_begin, vector<vector<int>>& mem)... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "int dp[1001][1001];\nclass Solution {\npublic:\n int util(string s, string t, int i, int j) {\n if (j == t.size()) return 1;\n if (i == s.size()) return 0;\n if (dp[i][j] != -1) return dp[i][j];\n int o1 = util(s, t, i + 1, j);\n int o2 = s[i] == t[j] ? util(s, t, i + ... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int numDistinct(string s, string t) {\n if(s.size()<t.size())return 0;\n vector<vector<int>> mem(s.size(),vector<int>(t.size(),-1));\n return solve(s,t,0,0,mem);\n }\n int solve(string s, string t, int s_begin, int t_begin, vector<vector<int>>& mem)... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n\n int dp[1001][1001];\n int solve(int i, int j, string s, string t)\n {\n if(j==t.size())\n {\n return 1;\n }\n if(i==s.size()) return 0;\n\n if(dp[i][j]!=-1) return dp[i][j];\n\n int nontake = solve(i+1,j,s,t);\n ... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int dp[1000][1000];\n int recursion(string s,string t,int i,int j){\n if(j>=t.length()) return 1;\n if(i>=s.length()) return 0;\n if(dp[i][j]!=-1) return dp[i][j];\n int way1=recursion(s,t,i+1,j);\n int way2=0;\n if(s[i]==t[j]) way... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\nint find(string s, string t,int i, int j, int dp[1003][1003]) {\n if(j==t.length()) {\n return 1;\n }\n if(i==s.length()){\n return 0;\n }\n if(dp[i][j]!=-1) {\n return dp[i][j];\n }\n int notchoose=find(s,t,i+1,j,dp);\n int choose=0;\... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int dp[1001][1001];\n int ans(int i,int j, string s, string t){\n int n=s.length(), m=t.length();\n if(j>=m) return 1;\n if(i>=n) return 0;\n if(dp[i][j]!=-1) return dp[i][j];\n int res = 0;\n res = ans(i+1,j,s,t);\n if(s[i]... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\n int dp[1001][1001];\n\n int solve(string s, string t, int i, int j) {\n if (j >= t.size()) return 1;\n if (i >= s.size()) return 0;\n if (dp[i][j] != -1) return dp[i][j];\n\n int ans = solve(s, t, i+1, j);\n if (s[i] == t[j]) ans += solve(s, t, i+... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int dp[1001][1001] ;\n\n int numDistinctHelper(int i, int j, string s, string t){\n if(j < 0) return 1 ;\n if(i < 0) return 0 ;\n if(dp[i][j] != -1) return dp[i][j] ;\n\n int ans = numDistinctHelper(i-1, j, s, t) ;\n\n if(s[i] == t[j]){\n... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\n int dp[1001][1001];\n int solve(string s,string t,int i,int j){\n if(j==0) return 1;\n if(i==0 )return 0;\n if(dp[i][j]!=-1){\n return dp[i][j];\n }\n\n if(s[i-1]==t[j-1]){ \n int ans1,ans2;\n if (dp[i-1][j-1]!=-1)... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int memo[1001][1001];\n int subsequence(string s, string t, int s_index, int t_index){\n if(t_index < 0) return 1;\n if(s_index < 0){\n return 0;\n }\n if(memo[s_index][t_index] != -1) return memo[s_index][t_index];\n int skip ... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int n,m;\n int dp[1001][1001];\n int solve(string s,string t,int i,int j){\n \n if(dp[i][j] != -1) return dp[i][j];\n\n if(j >= m) { \n return 1;\n }\n\n if(i >= n) return 0;\n int result = 0;\n \n if(s[... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int slen, tlen;\n int dp[1002][1002];\n int solve(int i , int j, string s, string t){\n if(j>=tlen){\n return 1;\n }\n if(i>=slen){\n return 0;\n }\n if(dp[i][j] != -1){\n return dp[i][j];\n }\n ... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int dp[1005][1005];\n int f(int i,int j,string s,string t){\n //base case\n if(j<0)return 1;\n if(i<0)return 0;\n if(dp[i][j]!=-1)return dp[i][j];\n int ans=0;\n if(s[i]==t[j]){\n ans+=f(i-1,j-1,s,t);\n ans+=f... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int s_size , t_size ;\n int solve(int i , int j , string s , string t , vector<vector<int>>&dp){\n if(i == t_size){\n return 1 ;\n }\n if(j == s_size){\n return 0 ;\n }\n if(dp[i][j] != -1) return dp[i][j] ;\n ... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\n int fun(int ind1,int ind2,string s,string t,vector<vector<int>>&dp){\n if(ind2<0){\n return 1;\n }\n if(ind1==0){\n if(ind2==0){\n return s[ind1]==t[ind2];\n }\n return 0;\n }\n if(dp[ind1][ind2]!=-1)return dp[ind1][... |
115 | <p>Given two strings s and t, return <i>the number of distinct</i> <b><i>subsequences</i></b><i> of </i>s<i> which equals </i>t.</p>
<p>The test cases are generated so that the answer fits on a 32-bit signed integer.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s... | 3 | {
"code": "class Solution {\npublic:\n int solve(string s, string t, int i, int j, vector<vector<int>> &dp){\n if(j < 0) return 1;\n if(i < 0) return 0;\n if(dp[i][j] != -1) return dp[i][j];\n\n int nottake = solve(s, t, i-1, j, dp);\n int take = 0;\n if(s[i] == t[j]) take... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 0 | {
"code": "class Solution {\n public:\n Node* connect(Node* root) {\n if (root == nullptr)\n return nullptr;\n connectTwoNodes(root->left, root->right);\n return root;\n }\n\n private:\n void connectTwoNodes(Node* p, Node* q) {\n if (p == nullptr)\n return;\n p->next = q;\n connectTwoNo... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 0 | {
"code": "class Solution {\n public:\n Node* connect(Node* root) {\n if (root == nullptr)\n return nullptr;\n connectTwoNodes(root->left, root->right);\n return root;\n }\n\n private:\n void connectTwoNodes(Node* p, Node* q) {\n if (p == nullptr)\n return;\n p->next = q;\n connectTwoNo... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 1 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 1 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 1 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 1 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 2 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 2 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
116 | <p>You are given a <strong>perfect binary tree</strong> where all leaves are on the same level, and every parent has two children. The binary tree has the following definition:</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next rig... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 0 | {
"code": "class Solution {\n public:\n Node* connect(Node* root) {\n Node* node = root; // the node that is above the current needling\n\n while (node != nullptr) {\n Node dummy(0); // the dummy node before needling\n // Needle the chi... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 0 | {
"code": "class Solution {\n public:\n Node* connect(Node* root) {\n Node* node = root; // the node that is above the current needling\n\n while (node != nullptr) {\n Node dummy(0); // the dummy node before needling\n // Needle the children of the node.\n for (Node* needle = &dummy; node; nod... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 0 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 0 | {
"code": "class Solution {\n public:\n Node* connect(Node* root) {\n Node* node = root; // the node that is above the current needling\n\n while (node != nullptr) {\n Node dummy(0); // the dummy node before needling\n // Needle the children of the node.\n for (Node* needle = &dummy; node; nod... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 1 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 1 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 2 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 2 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 3 | {
"code": "/*\n// Definition for a Node.\nclass Node {\npublic:\n int val;\n Node* left;\n Node* right;\n Node* next;\n\n Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n Node(int _val, Node* _left, Node* _right, No... |
117 | <p>Given a binary tree</p>
<pre>
struct Node {
int val;
Node *left;
Node *right;
Node *next;
}
</pre>
<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code>NULL</code>.</p>
<p>Initially, all next pointers are set to <code>NULL</... | 3 | {
"code": "class Solution {\n\tpublic:\n\t\tNode* connect(Node* root) {\n\t\t\tif(!root) return NULL;\n\n\t\t\tvector<vector<Node*>> lvl;\n\t\t\tqueue <Node*> q;\n\t\t\tq.push(root);\n\n\t\t\twhile(!q.empty()){\n\t\t\t\tint size = q.size();\n\t\t\t\tvector <Node*> temp;\n\n\t\t\t\tfor(int i = 0 ; i < size ; i++){\n\t... |
118 | <p>Given an integer <code>numRows</code>, return the first numRows of <strong>Pascal's triangle</strong>.</p>
<p>In <strong>Pascal's triangle</strong>, each number is the sum of the two numbers directly above it as shown:</p>
<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAn... | 0 | {
"code": "long long int factorial(int n)\n{\n long long int res = 1, i;\n for (i = 1; i <= n; i++)\n res *= i;\n return res;\n}\nunsigned nck( unsigned n, unsigned k )\n{\n if (k > n) return 0;\n if (k * 2 > n) k = n-k;\n if (k == 0) return 1;\n\n int result = n;\n for( int i = 2; i <=... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.