Decode Ways (LeetCode 91) | Full Solution with visuals | Recursion to Dynamic Programming

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ธ.ค. 2024

ความคิดเห็น • 33

  • @lamebert
    @lamebert 5 หลายเดือนก่อน +9

    This is insane, i wasnt able to understand the neetcode solution, but i am able to understand this! Thanks

    • @thisissheraf2633
      @thisissheraf2633 4 หลายเดือนก่อน +1

      NeetCode is also good, however, this is a simplified version with a dp array, and coming up with this solution in an unseen problem is very difficult.
      Please develop the understanding with recursion + memoization as explained by neetcode, it will be very helpful long term.

    • @LinhHoang-ml1qo
      @LinhHoang-ml1qo 4 หลายเดือนก่อน

      ​@@thisissheraf2633 Agree!

  • @chandan07talreja
    @chandan07talreja 9 หลายเดือนก่อน +4

    Thanks for detailed explanation Nikhil. Really appreciate it.

  • @Md_sadiq_Md
    @Md_sadiq_Md 9 หลายเดือนก่อน +3

    Pushing the algorithm

  • @gamasterprochannel856
    @gamasterprochannel856 4 หลายเดือนก่อน +3

    This man is genius

  • @yomamasofat413
    @yomamasofat413 4 หลายเดือนก่อน

    bro who would be able to come up with this solution if he has never seen it before in an interview? Crazy man

  • @rudreshcm4172
    @rudreshcm4172 9 หลายเดือนก่อน +4

    Hey nikhil, first of all thanks for your top notch leetcode video solutions. Can you please make one video that should provide roadmap specific to your uploaded playlists/videos. This really make difference and increase watch count.

    • @nikoo28
      @nikoo28  8 หลายเดือนก่อน +1

      I have created some playlists, but yes...can define a better roadmap too. Will work on it. Thanks. :)

  • @satyadharkumarchintagunta3793
    @satyadharkumarchintagunta3793 2 หลายเดือนก่อน

    Thanks bro! Neat and clear explanation.

  • @banadipmudi3186
    @banadipmudi3186 2 หลายเดือนก่อน

    Thanks brother, amazing explanation

  • @floatingfortress721
    @floatingfortress721 6 หลายเดือนก่อน +1

    Thank you very much! You were able to simplify the problem for me and now I actually understand it

  • @Satya-g5t
    @Satya-g5t 2 หลายเดือนก่อน

    always good explanation, consistent and patient with no hurry, cool. 😃

  • @nivedhitha704
    @nivedhitha704 4 หลายเดือนก่อน +1

    very very perfect solution....i love this explanation...u made it very easy to understand for beginners...thank you so much sir

  • @sanjith3075
    @sanjith3075 3 หลายเดือนก่อน

    this video cleared my doubts , tqsm

  • @akshaygupta5290
    @akshaygupta5290 23 วันที่ผ่านมา

    Best explanation

  • @KoundinyaKoorapati-o8v
    @KoundinyaKoorapati-o8v 3 หลายเดือนก่อน

    Nikhil you make things so simple. I really wish you conducted some course in DSA. Thank You.

  • @shubhamsharma8820
    @shubhamsharma8820 5 หลายเดือนก่อน

    very well explained

  • @prashanthshetty8337
    @prashanthshetty8337 8 หลายเดือนก่อน +1

    Thank you very much for the detailed explanation. instead of dp[], we could use 2 place holders to keep track of previous sum right? all we care is i-1 and i-2 can be tracked as prev1 and prev2.

    • @nikoo28
      @nikoo28  8 หลายเดือนก่อน +1

      That's a great idea! Will save you space.

  • @akshitjain2906
    @akshitjain2906 6 หลายเดือนก่อน +1

    legend

  • @Techgether
    @Techgether 5 หลายเดือนก่อน +2

    "dp[0] = 1 because there is 1 way to decode it, which is not doing anything"... this is not doing anything but still counted as 1 way????? kinda contradict when its only counted as 1 if there is something to decode, which is why when digit is 0, there is 0 way to decode.. but when digit is empty which is at 0 index, now its counted as 1.. this is hard to understand..

    • @benmyths
      @benmyths 3 หลายเดือนก่อน +1

      also in counting stair problem there was a base condition where when you are standing on 0th stairs, theres only 1 way to reach it that is by doing nothing. so dp[0] = 1 😂😂😂 man its so confusing

  • @GmHighlight12
    @GmHighlight12 7 หลายเดือนก่อน

    What if String length only 2 this code will failed to execute

    • @SevDeuceOff
      @SevDeuceOff 7 หลายเดือนก่อน

      I tested with string length as 2. It works. Can you share specific examples that failed for you ?

    • @GmHighlight12
      @GmHighlight12 7 หลายเดือนก่อน

      Try to run this code on leetcode all test cases won’t pass

    • @SevDeuceOff
      @SevDeuceOff 7 หลายเดือนก่อน

      @@GmHighlight12 It does pass all test cases.
      I tore the code to determine the breakage point. Looks like you may be hinting at the test case "10". Is that the one ?

    • @sriyanandakuchimanchi4042
      @sriyanandakuchimanchi4042 6 หลายเดือนก่อน

      no it will work
      instead of writing dp[1] like that.,,add this check
      if(s.charAt(0)=='0'||s.length==0||s==null){
      return 0;
      }

  • @tamils12345
    @tamils12345 7 หลายเดือนก่อน

    class Solution {
    public:
    int numDecodings(string s) {
    vector dp(s.length() + 1);
    dp[0] = 1;
    dp[1] = (s.at(0) == '0')?0:1;
    for(int i = 2; i= 1) {
    dp[i] += dp[i-1];
    }
    if (double_digit >= 10 && double_digit

    • @jst8922
      @jst8922 6 หลายเดือนก่อน +1

      The issue stems from how you're extracting single and double-digit numbers using stoi and substr.
      Here's a breakdown of the problem and the solution:
      Problem:
      Incorrect Substring Extraction: The substr(i-1, i) in stoi(s.substr(i-1, i)) doesn't extract a single digit. Instead, it extracts a substring from index i-1 up to (but not including) index i. This means you're always getting a two-character substring (except for the last iteration).
      Unnecessary stoi: You don't need stoi to check if a single digit is between 1 and 9. A simple character comparison is more efficient.
      tested & working on lc
      class Solution {
      public:
      int numDecodings(string s) {
      int n = s.length();
      vector dp(n + 1);
      dp[0] = 1; // Empty substring has one way to decode
      dp[1] = (s[0] == '0') ? 0 : 1; // First digit can't be '0'
      for (int i = 2; i = 1 && single_digit = 10 && double_digit

    • @tamils12345
      @tamils12345 6 หลายเดือนก่อน

      @@jst8922 thanks man.

    • @imdarkseid2343
      @imdarkseid2343 4 หลายเดือนก่อน

      ​@@tamils12345 Bro neenga final year ah bro

    • @tamils12345
      @tamils12345 4 หลายเดือนก่อน

      @@imdarkseid2343 no. Working