Decode Ways | Recursion | Memo | Bottom Up | Leetcode 91

Поділитися
Вставка
  • Опубліковано 4 січ 2025

КОМЕНТАРІ • 77

  • @DevOpskagyaan
    @DevOpskagyaan Рік тому +16

    Give this guy an Award 🫡❤️
    Hats off to such a detailed explanation 🙌

  • @ManishGupta-lz8ho
    @ManishGupta-lz8ho Рік тому +3

    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😊

  • @aws_handles
    @aws_handles Рік тому +17

    Netflix ❌
    MIK’s Long Detailed Videos ✅

  • @wearevacationuncoverers
    @wearevacationuncoverers Рік тому +1

    Just completed the video. Bottom Up ka fear bhaga Diya sir apne. Tussi great ho.

  • @sauravchandra10
    @sauravchandra10 Рік тому +6

    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

  • @wearevacationuncoverers
    @wearevacationuncoverers Рік тому +13

    Sir weekly contest ka Qn-3 banado please. Aapse acha koi nahi samjhata.

    • @bhuppidhamii
      @bhuppidhamii Рік тому +1

      +1

    • @codestorywithMIK
      @codestorywithMIK  Рік тому +2

      Weekly Contest 377 Qn - 3
      ua-cam.com/video/M8WnAIhTjmQ/v-deo.htmlsi=U8onTOhsee0T7Q7M

  • @abhayshukla322
    @abhayshukla322 11 місяців тому

    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 🙏

  • @SrishtiKapoor-d1w
    @SrishtiKapoor-d1w 5 місяців тому +1

    Amazing explanation

  • @souravjoshi2293
    @souravjoshi2293 Рік тому +1

    You killed bottom up dude. No one can make tough topics easy like you do.

  • @nibaronkumar2484
    @nibaronkumar2484 Рік тому +1

    Pura Bawal vaiya 🔥🔥

  • @yashkalia2311
    @yashkalia2311 9 місяців тому +1

    Great video

  • @anuppatankar4294
    @anuppatankar4294 Рік тому +2

    Great video 👌

  • @aws_handles
    @aws_handles Рік тому

    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 🙌🔥

  • @monikavaid5083
    @monikavaid5083 Рік тому +2

    Very detailed and easy to understand explanation

  • @qR7pK9sJ2t
    @qR7pK9sJ2t 11 місяців тому +2

    Yrr you have such a soothing voice..
    Please try in dubbing /RJ roles as well..
    And you can continue to post videos as well..

  • @omgupta7712
    @omgupta7712 Рік тому +1

    Sir solved by own top tup approach thanks sir

  • @Shivanai_h
    @Shivanai_h Рік тому +1

    Best explanation on

  • @umeshbisht1054
    @umeshbisht1054 Рік тому +1

    Thanku bhaiya ❤

  • @-OmkarSawant-pe2uq
    @-OmkarSawant-pe2uq Рік тому +1

    Great !!!!

  • @sparshyadav9709
    @sparshyadav9709 5 місяців тому +1

    Understood.

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 Рік тому +1

    advance congratulations of 14k+ subscription.

  • @ankitsahu2305
    @ankitsahu2305 Рік тому +1

    Nice explanation

  • @pragatijadhav26
    @pragatijadhav26 Рік тому +3

    its request please provide solution and explanation of weekly and biweekly contest questions also.

    • @codestorywithMIK
      @codestorywithMIK  Рік тому +1

      Weekly Contest 377 Qn - 3
      ua-cam.com/video/M8WnAIhTjmQ/v-deo.htmlsi=U8onTOhsee0T7Q7M

  • @kingreja5894
    @kingreja5894 Рік тому +1

    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)

  • @chayandas9191
    @chayandas9191 Рік тому +3

    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

  • @JoyAcharyatvl
    @JoyAcharyatvl Рік тому +1

    awesome bro

  • @akshanshsharma6025
    @akshanshsharma6025 Рік тому +2

    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

    • @codestorywithMIK
      @codestorywithMIK  Рік тому

      Weekly Contest 377 Qn - 3
      ua-cam.com/video/M8WnAIhTjmQ/v-deo.htmlsi=U8onTOhsee0T7Q7M

    • @akshanshsharma6025
      @akshanshsharma6025 Рік тому

      @@codestorywithMIK thanks bro hope you covered all the questions of contest

  • @theOmKumar
    @theOmKumar Рік тому

    thank you!

  • @codeandtalk6
    @codeandtalk6 Рік тому +1

    ❤❤❤

  • @sujalgupta6100
    @sujalgupta6100 Рік тому

    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

    • @divyanshmishra5121
      @divyanshmishra5121 6 місяців тому

      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

  • @adarshrathore9960
    @adarshrathore9960 Рік тому +1

    Sir please contests ke 3rd, 4th questions ki bhi videos banaiye 🙏

    • @codestorywithMIK
      @codestorywithMIK  Рік тому

      Weekly Contest 377 Qn - 3
      ua-cam.com/video/M8WnAIhTjmQ/v-deo.htmlsi=U8onTOhsee0T7Q7M

  • @MakeuPerfect
    @MakeuPerfect 11 місяців тому

    dp[i] -> no. of decode ways till length i
    can we solve using this state ? How???

  • @bhartendupant8859
    @bhartendupant8859 Рік тому +1

  • @tutuimam3381
    @tutuimam3381 Рік тому +1

    Thanks 👍

  • @AnupGupta-z9x
    @AnupGupta-z9x Рік тому +1

    aazadi ka 75th mahotsav
    😅

  • @AmarjeetKumar-to9ub
    @AmarjeetKumar-to9ub Рік тому +2

    🔥++

  • @RiyazParve
    @RiyazParve Рік тому +1

    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 ?

    • @whogopu
      @whogopu 10 днів тому

      @codestorywithMIK same doubt

  • @ammanchhetri6716
    @ammanchhetri6716 Рік тому +1

    i was able to solve dis....till space optimization 😪

  • @vamsimadugula8524
    @vamsimadugula8524 Рік тому

    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

  • @Raj10185
    @Raj10185 Рік тому +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);


    }
    };

  • @siddharthmishra8651
    @siddharthmishra8651 Рік тому +1

    bhai please java ka bhi explain krna video m...:(

  • @phoenixRisen4739
    @phoenixRisen4739 Рік тому +1

    Follow up decode ways 2

  • @anandpandey918
    @anandpandey918 2 місяці тому +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
      @codestorywithMIK  2 місяці тому +1

      So happy to see you tried brute force ♥️

    • @anandpandey918
      @anandpandey918 2 місяці тому

      @@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!

  • @vikashtiwari1521
    @vikashtiwari1521 Рік тому

    Kya ye question sirf dp se hi solve ho sakta hai

    • @souravjoshi2293
      @souravjoshi2293 Рік тому +1

      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

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 Рік тому +1

    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

  • @prudhvirajmacherla9854
    @prudhvirajmacherla9854 Рік тому +1

    @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

    • @codestorywithMIK
      @codestorywithMIK  Рік тому

      Hi there,
      Actually i have never contributed on leetcode before. That’s why I am also not sure. But let me check

  • @SrishtiKapoor-d1w
    @SrishtiKapoor-d1w 5 місяців тому +1

    Amazing explanation