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

Поделиться
HTML-код
  • Опубликовано: 1 окт 2024

Комментарии • 29

  • @lamebert
    @lamebert 2 месяца назад +6

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

    • @thisissheraf2633
      @thisissheraf2633 Месяц назад +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 Месяц назад

      ​@@thisissheraf2633 Agree!

  • @Techgether
    @Techgether 2 месяца назад +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 19 дней назад

      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

  • @gamasterprochannel856
    @gamasterprochannel856 Месяц назад +3

    This man is genius

  • @rudreshcm4172
    @rudreshcm4172 6 месяцев назад +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  5 месяцев назад +1

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

  • @chandan07talreja
    @chandan07talreja 6 месяцев назад +3

    Thanks for detailed explanation Nikhil. Really appreciate it.

  • @KoundinyaKoorapati-o8v
    @KoundinyaKoorapati-o8v 4 дня назад

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

  • @nivedhitha704
    @nivedhitha704 Месяц назад +1

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

  • @floatingfortress721
    @floatingfortress721 3 месяца назад +1

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

  • @Md_sadiq_Md
    @Md_sadiq_Md 6 месяцев назад +3

    Pushing the algorithm

  • @sanjith3075
    @sanjith3075 22 дня назад

    this video cleared my doubts , tqsm

  • @prashanthshetty8337
    @prashanthshetty8337 5 месяцев назад +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  5 месяцев назад +1

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

  • @akshitjain2906
    @akshitjain2906 3 месяца назад +1

    legend

  • @yomamasofat413
    @yomamasofat413 2 месяца назад

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

  • @shubhamsharma8820
    @shubhamsharma8820 2 месяца назад

    very well explained

  • @tamils12345
    @tamils12345 4 месяца назад

    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 3 месяца назад +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 3 месяца назад

      @@jst8922 thanks man.

    • @imdarkseid2343
      @imdarkseid2343 2 месяца назад

      ​@@tamils12345 Bro neenga final year ah bro

    • @tamils12345
      @tamils12345 2 месяца назад

      @@imdarkseid2343 no. Working

  • @GmHighlight12
    @GmHighlight12 4 месяца назад

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

    • @SevDeuceOff
      @SevDeuceOff 4 месяца назад

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

    • @GmHighlight12
      @GmHighlight12 4 месяца назад

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

    • @SevDeuceOff
      @SevDeuceOff 4 месяца назад

      @@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 4 месяца назад

      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;
      }