Was able to solve this on my own! Thanks to your previous videos for teaching me the concept. My implementation: class Solution { public: int dp[101]; int solve(int ind, string &s){ if(ind==s.size()) return 1; if(dp[ind]!=-1) return dp[ind]; int ans=0; int num=s[ind]-'0'; if(num!=0){ ans+=solve(ind+1,s); } if((num==1 || num==2) && ind
Bhau jis trah se aap samjhate ho mja aa jata hai mai tree diagram toh pohonch gyabtha but yeh conditions banane me problem after this I am feeling confident thank you 🙏
Just like my fear of Graph is gone because of your Graph playlist, My fear of bottom Up DP is slowly going because of you. I came here to see bottom up and you nailed it 🙌🔥
Just by looking at the logic of recursion from the beginning, I understood your approach. Thankyou so much for clarification bhaiya, here is my code : public int numDecodings(String s) { int n = s.length(); int[] dp = new int[n+1]; dp[n] =1; for(int i = n-1;i>=0;i--){ if(s.charAt(i)=='0'){ dp[i] = 0; }else{ int oneDigit = dp[i+1]; int twoDigit =0; if( i+1 < n && ((s.charAt(i)=='1') || (s.charAt(i)=='2' && s.charAt(i+1)
Please check one biweekly contest question,count the number of incremovable subarray,its difficult to understand how to take the approach,plz check it once if possible sir
bro i request you to please start making weekly and biweekly contest videos too it will be great helpful and if you start live stream that will be super helpful
Thanks for the explantion of tabulation. in approach 2 (tabulation) on Github it says time and space as both to be o(n) but in this way, memoization is more optimal as it has O(n) time and O(1) space Also, I couldn't understand the approach 3(bottom up 2) and approach 4 //t[i] = ways to decode string of length i t[0] = 1; why is there no check if t[0] is '0' or '1' ? One more thing is that, I always stuggle to identify time complexity in question invloving complex data structure or question which involve recursion or solution. I have learnt time complexity concept multiple times, but they always teach easy snippets to explain, but don't explain how to find time and space in lets say Trie Questions. Any remedy for this would help because I want to learn how you tell the time complexity in one go. thanks
you're ignoring the auxiliary stack space for memoization part. for the second doubt, for this part //t[i] = ways to decode string of length i. hence t[0] is actually string of length 0 means no string actually. for t[1] is a string of length 1 which might be '0' hence we're checking
Space Complexity : O(1) class Solution { public: int numDecodings(string s) { int n = s.length(); int prev=1,prev2=0; for(int ind=n-1;ind>=0;ind--){ int curr = 0; if(s[ind]!='0'){ curr = prev; if(ind+1
//Bruteforce Approach class Solution { public int numDecodings(String str) { return numDecodingsHelper(str); } private int numDecodingsHelper(String str) { // Base case: If the string is empty, we have found one valid decoding if (str.isEmpty()) { return 1; // Return 1 for this valid decoding } int count = 0; for (int i = 0; i < str.length(); i++) { if (isValidPartition(str.substring(0, i + 1))) { count += numDecodingsHelper(str.substring(i + 1)); } } return count; } private boolean isValidPartition(String str) { if (str.length() > 2) { return false; // If the length of the string is greater than 2, it's invalid } if (str.charAt(0) == '0') { return false; // Invalid if the number has a leading zero } int num = Integer.parseInt(str); return num >= 1 && num 2) { return false; } if (str.charAt(start) == '0') { return false; } int num = Integer.parseInt(str.substring(start, end + 1)); return num >= 1 && num 2) { return false; } if (str.charAt(start) == '0') { return false; } int num = Integer.parseInt(str.substring(start, end + 1)); return num >= 1 && num
@@codestorywithMIK Went through first 5 minutes of your video and afterwards I was able to code all the approaches by myself....from very naive to most optimal. Thankyou bhaiya!!! 'Minimum window subsequence' karke ek question hai leet code pai...please is question par ek video bana dijiye aap!
There is one constant space solution. BUT, if you see, the approach is actually internally using past results (which is nothing but DP only) Reference - MIK's Github Repo (Approach-4) class Solution { public: int numDecodings(string s) { int n = s.length(); if(n == 1) return s[0] == '0' ? 0 : 1; if(s[0] == '0') return 0; int last1 = 1, last2 = 1; for(int i = 1; i
@codestorywithMIK i want to contribute a qns in leetcode can u help me i have previously contributed a qn to leetcode 9 months back but it is in still pending
Give this guy an Award 🫡❤️
Hats off to such a detailed explanation 🙌
yr aap addictive ho question khud se ho bhi jaaye phir your solution really kuch na kuch extra samjha hi jaata like itna bhi hard nhi sochna tha😊
Netflix ❌
MIK’s Long Detailed Videos ✅
tru
💯
Just completed the video. Bottom Up ka fear bhaga Diya sir apne. Tussi great ho.
Was able to solve this on my own! Thanks to your previous videos for teaching me the concept.
My implementation:
class Solution {
public:
int dp[101];
int solve(int ind, string &s){
if(ind==s.size()) return 1;
if(dp[ind]!=-1) return dp[ind];
int ans=0;
int num=s[ind]-'0';
if(num!=0){
ans+=solve(ind+1,s);
}
if((num==1 || num==2) && ind
❤️🙏😇
Sir weekly contest ka Qn-3 banado please. Aapse acha koi nahi samjhata.
+1
Weekly Contest 377 Qn - 3
ua-cam.com/video/M8WnAIhTjmQ/v-deo.htmlsi=U8onTOhsee0T7Q7M
Bhau jis trah se aap samjhate ho mja aa jata hai mai tree diagram toh pohonch gyabtha but yeh conditions banane me problem after this I am feeling confident thank you 🙏
Amazing explanation
You killed bottom up dude. No one can make tough topics easy like you do.
Pura Bawal vaiya 🔥🔥
Great video
Great video 👌
Thank you 😇❤️
Just like my fear of Graph is gone because of your Graph playlist,
My fear of bottom Up DP is slowly going because of you. I came here to see bottom up and you nailed it 🙌🔥
Very detailed and easy to understand explanation
Glad it was helpful! 🙏🙏😇
Yrr you have such a soothing voice..
Please try in dubbing /RJ roles as well..
And you can continue to post videos as well..
Means a lot ❤️❤️🙏🙏
Sir solved by own top tup approach thanks sir
❤️🙏😇
Best explanation on
Thank you 🙏😇
Thanku bhaiya ❤
Great !!!!
Understood.
advance congratulations of 14k+ subscription.
Thank you so much 😀
Nice explanation
😇🙏
its request please provide solution and explanation of weekly and biweekly contest questions also.
Weekly Contest 377 Qn - 3
ua-cam.com/video/M8WnAIhTjmQ/v-deo.htmlsi=U8onTOhsee0T7Q7M
Just by looking at the logic of recursion from the beginning, I understood your approach. Thankyou so much for clarification bhaiya,
here is my code :
public int numDecodings(String s) {
int n = s.length();
int[] dp = new int[n+1];
dp[n] =1;
for(int i = n-1;i>=0;i--){
if(s.charAt(i)=='0'){
dp[i] = 0;
}else{
int oneDigit = dp[i+1];
int twoDigit =0;
if( i+1 < n && ((s.charAt(i)=='1') || (s.charAt(i)=='2' && s.charAt(i+1)
Please check one biweekly contest question,count the number of incremovable subarray,its difficult to understand how to take the approach,plz check it once if possible sir
Noted. Let me check this week only ✌️
@@codestorywithMIK means a lot sir❤️
awesome bro
Thank you ❤️🙏😇
bro i request you to please start making weekly and biweekly contest videos too it will be great helpful and if you start live stream that will be super helpful
Weekly Contest 377 Qn - 3
ua-cam.com/video/M8WnAIhTjmQ/v-deo.htmlsi=U8onTOhsee0T7Q7M
@@codestorywithMIK thanks bro hope you covered all the questions of contest
thank you!
❤❤❤
Thanks for the explantion of tabulation.
in approach 2 (tabulation) on Github
it says time and space as both to be o(n)
but in this way, memoization is more optimal as it has O(n) time and O(1) space
Also, I couldn't understand the approach 3(bottom up 2) and approach 4
//t[i] = ways to decode string of length i
t[0] = 1;
why is there no check if t[0] is '0' or '1' ?
One more thing is that, I always stuggle to identify time complexity in question invloving complex data structure or question which involve recursion or solution. I have learnt time complexity concept multiple times, but they always teach easy snippets to explain, but don't explain how to find time and space in lets say Trie Questions. Any remedy for this would help because I want to learn how you tell the time complexity in one go.
thanks
you're ignoring the auxiliary stack space for memoization part. for the second doubt, for this part //t[i] = ways to decode string of length i. hence t[0] is actually string of length 0 means no string actually. for t[1] is a string of length 1 which might be '0' hence we're checking
Sir please contests ke 3rd, 4th questions ki bhi videos banaiye 🙏
Weekly Contest 377 Qn - 3
ua-cam.com/video/M8WnAIhTjmQ/v-deo.htmlsi=U8onTOhsee0T7Q7M
dp[i] -> no. of decode ways till length i
can we solve using this state ? How???
❤
Thanks 👍
aazadi ka 75th mahotsav
😅
🔥++
I am not able to understand why t[n] = 1.
If s="0" then t[n]=0 how can we assume it will be 1 ?
@codestorywithMIK same doubt
i was able to solve dis....till space optimization 😪
Space Complexity : O(1)
class Solution {
public:
int numDecodings(string s) {
int n = s.length();
int prev=1,prev2=0;
for(int ind=n-1;ind>=0;ind--){
int curr = 0;
if(s[ind]!='0'){
curr = prev;
if(ind+1
My simple solution :-
class Solution {
public:
int dp[101];
int solve(int idx , string s )
{
if(idx==s.size())
{
return 1;
}
if(s[idx]=='0')
return 0;
if(dp[idx] != -1)
return dp[idx];
//way 1 => take 1 char at time
int count = 0;
count = solve(idx+1 ,s);
//way 2 take substring of size 2 but substr must be < "27"
if(idx< s.size()-1 && s.substr(idx,2) < "27")
{
count += solve(idx+2 ,s);
}
return dp[idx] = count;
}
int numDecodings(string s) {
memset(dp,-1,sizeof(dp));
return solve(0,s);
}
};
bhai please java ka bhi explain krna video m...:(
Noted 👌
Follow up decode ways 2
Let me check soon 🙏
//Bruteforce Approach
class Solution {
public int numDecodings(String str) {
return numDecodingsHelper(str);
}
private int numDecodingsHelper(String str) {
// Base case: If the string is empty, we have found one valid decoding
if (str.isEmpty()) {
return 1; // Return 1 for this valid decoding
}
int count = 0;
for (int i = 0; i < str.length(); i++) {
if (isValidPartition(str.substring(0, i + 1))) {
count += numDecodingsHelper(str.substring(i + 1));
}
}
return count;
}
private boolean isValidPartition(String str) {
if (str.length() > 2) {
return false; // If the length of the string is greater than 2, it's invalid
}
if (str.charAt(0) == '0') {
return false; // Invalid if the number has a leading zero
}
int num = Integer.parseInt(str);
return num >= 1 && num 2) {
return false;
}
if (str.charAt(start) == '0') {
return false;
}
int num = Integer.parseInt(str.substring(start, end + 1));
return num >= 1 && num 2) {
return false;
}
if (str.charAt(start) == '0') {
return false;
}
int num = Integer.parseInt(str.substring(start, end + 1));
return num >= 1 && num
So happy to see you tried brute force ♥️
@@codestorywithMIK Went through first 5 minutes of your video and afterwards I was able to code all the approaches by myself....from very naive to most optimal.
Thankyou bhaiya!!!
'Minimum window subsequence' karke ek question hai leet code pai...please is question par ek video bana dijiye aap!
Kya ye question sirf dp se hi solve ho sakta hai
There is one constant space solution.
BUT, if you see, the approach is actually internally using past results (which is nothing but DP only)
Reference - MIK's Github Repo (Approach-4)
class Solution {
public:
int numDecodings(string s) {
int n = s.length();
if(n == 1)
return s[0] == '0' ? 0 : 1;
if(s[0] == '0')
return 0;
int last1 = 1, last2 = 1;
for(int i = 1; i
public int numDecodings (String s){
if (s.charAt(0)=='0') return 0;
int n=s.length();
int[]dp=new int [n+1];
dp[0]=1;dp[1]=1;
for(int i=2;i
@codestorywithMIK i want to contribute a qns in leetcode can u help me i have previously contributed a qn to leetcode 9 months back but it is in still pending
Hi there,
Actually i have never contributed on leetcode before. That’s why I am also not sure. But let me check
Amazing explanation