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

  Рет қаралды 7,263

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Пікірлер: 32
@lamebert
@lamebert 4 ай бұрын
This is insane, i wasnt able to understand the neetcode solution, but i am able to understand this! Thanks
@thisissheraf2633
@thisissheraf2633 2 ай бұрын
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 2 ай бұрын
​@@thisissheraf2633 Agree!
@gamasterprochannel856
@gamasterprochannel856 3 ай бұрын
This man is genius
@chandan07talreja
@chandan07talreja 8 ай бұрын
Thanks for detailed explanation Nikhil. Really appreciate it.
@Md_sadiq_Md
@Md_sadiq_Md 8 ай бұрын
Pushing the algorithm
@yomamasofat413
@yomamasofat413 3 ай бұрын
bro who would be able to come up with this solution if he has never seen it before in an interview? Crazy man
@nivedhitha704
@nivedhitha704 2 ай бұрын
very very perfect solution....i love this explanation...u made it very easy to understand for beginners...thank you so much sir
@floatingfortress721
@floatingfortress721 5 ай бұрын
Thank you very much! You were able to simplify the problem for me and now I actually understand it
@rudreshcm4172
@rudreshcm4172 8 ай бұрын
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 7 ай бұрын
I have created some playlists, but yes...can define a better roadmap too. Will work on it. Thanks. :)
@Satya-g5t
@Satya-g5t Ай бұрын
always good explanation, consistent and patient with no hurry, cool. 😃
@banadipmudi3186
@banadipmudi3186 Ай бұрын
Thanks brother, amazing explanation
@KoundinyaKoorapati-o8v
@KoundinyaKoorapati-o8v Ай бұрын
Nikhil you make things so simple. I really wish you conducted some course in DSA. Thank You.
@satyadharkumarchintagunta3793
@satyadharkumarchintagunta3793 29 күн бұрын
Thanks bro! Neat and clear explanation.
@sanjith3075
@sanjith3075 2 ай бұрын
this video cleared my doubts , tqsm
@shubhamsharma8820
@shubhamsharma8820 3 ай бұрын
very well explained
@akshitjain2906
@akshitjain2906 5 ай бұрын
legend
@prashanthshetty8337
@prashanthshetty8337 7 ай бұрын
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 7 ай бұрын
That's a great idea! Will save you space.
@Techgether
@Techgether 4 ай бұрын
"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 2 ай бұрын
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
@tamils12345
@tamils12345 6 ай бұрын
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 5 ай бұрын
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 5 ай бұрын
@@jst8922 thanks man.
@imdarkseid2343
@imdarkseid2343 3 ай бұрын
​@@tamils12345 Bro neenga final year ah bro
@tamils12345
@tamils12345 3 ай бұрын
@@imdarkseid2343 no. Working
@GmHighlight12
@GmHighlight12 6 ай бұрын
What if String length only 2 this code will failed to execute
@SevDeuceOff
@SevDeuceOff 6 ай бұрын
I tested with string length as 2. It works. Can you share specific examples that failed for you ?
@GmHighlight12
@GmHighlight12 6 ай бұрын
Try to run this code on leetcode all test cases won’t pass
@SevDeuceOff
@SevDeuceOff 6 ай бұрын
@@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 5 ай бұрын
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; }
ТЮРЕМЩИК В БОКСЕ! #shorts
00:58
HARD_MMA
Рет қаралды 2,6 МЛН
Disrespect or Respect 💔❤️
00:27
Thiago Productions
Рет қаралды 43 МЛН
Turn Off the Vacum And Sit Back and Laugh 🤣
00:34
SKITSFUL
Рет қаралды 3,1 МЛН
91. Decode Ways | 3 Ways
27:30
Aryan Mittal
Рет қаралды 3,4 М.
Decode Ways - LeetCode 91 - Python
12:12
DEEPTI TALESRA
Рет қаралды 754
Coding Interview Problem - Decode Ways
13:53
Knapsack
Рет қаралды 19 М.
ТЮРЕМЩИК В БОКСЕ! #shorts
00:58
HARD_MMA
Рет қаралды 2,6 МЛН