Decode Ways Dynamic Programming | Total Ways to Decode a String | Count Encodings

Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, we discuss the Count Encodings problem where we are required to count and print all the encodings for a string as per the codes given in the question.
In this problem,
1. You are given a string str of digits. (will never start with a 0)
2. You are required to encode the str as per following rules
1 - a
2 - b
3 - c
..
25 - y
26 - z
3. You are required to calculate and print the count of encodings for the string str.
For 123 - there are 3 encodings. abc, aw, lc
For 993 - there is 1 encoding. iic
For 013 - This is an invalid input. A string starting with 0 will not be passed.
For 103 - there is 1 encoding. jc
For 303 - there are 0 encodings. But such a string maybe passed. In this case
print 0.
To submit this question, click here: www.pepcoding.com/resources/o...
For a better experience and more exercises, VISIT: www.pepcoding.com/resources/o...
#dp #decodeways #dynamicprogramming
Have a look at our result: www.pepcoding.com/placements
Follow us on our FB page: / pepcoding
Follow us on Instagram: / pepcoding
Follow us on LinkedIn: / pepcoding-education

Пікірлер: 203

  • @rajk.4530
    @rajk.4530 Жыл бұрын

    when I was in college in 2012, there was no good content on the internet, Even the net was not so cheap at that time :P. but now I am seeing you guys putting this much effort into knowledge sharing is amazing. Today students are lucky to have instructors like you. Kudos, keep up the good work.

  • @manishdalal1914
    @manishdalal19144 ай бұрын

    most under rated teacher on youtube

  • @rishabhkesarwani5761
    @rishabhkesarwani57613 жыл бұрын

    MOST Underrated Channel on KZread!!

  • @RaviYadav-bt2eg
    @RaviYadav-bt2eg3 жыл бұрын

    Very concise and informative video. That repetitive "chik hai" instead of "thik hai" though🤣

  • @ayannaskar9195

    @ayannaskar9195

    2 жыл бұрын

    why did u point it out!! Now i cant avoid hearing it😂

  • @anmolsharma9539

    @anmolsharma9539

    Жыл бұрын

    Are bhai kya btaa diya bc bar bar ussi pe dhyan chala jata hai😂

  • @yashwantkumar9929
    @yashwantkumar99293 жыл бұрын

    The way you teach is just amazing sir, you make every single line of code easy, Big Thank you. Pepcoding is going to be a big brand in these coming days.

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    So nice of you!! aage bdtte rhiee and share as much as you can

  • @curiouswatcher4626
    @curiouswatcher46262 жыл бұрын

    Sir , amazing explaination !! Aap ek complex problem ko piece by piece aise explain kar dete ho jaise kuch ho hi nahi . Big fan Sumeet sir !

  • @divyanshpant169
    @divyanshpant1692 жыл бұрын

    Starting 5 mins gave me enough idea how to solve it. Thanks a lot. I refer to ur videos first.

  • @sameerkumargupta6058
    @sameerkumargupta60582 жыл бұрын

    you are the best guy, making free tutorial

  • @gagankhurana2049
    @gagankhurana20493 жыл бұрын

    Great explanation.Really, hats off Sumit Sir.

  • @NewMovieTrailersTransformed
    @NewMovieTrailersTransformed2 жыл бұрын

    I would like to thank you for this question plus I was interviewed at one place where I explained the same way how you did and they were impressed, all because of you keep doing the good work. :)

  • @Pepcoding

    @Pepcoding

    2 жыл бұрын

    Glad it helped! Keep learning. And for better experience, visit nados.io, where you will get well curated content and career opportunities.

  • @deepanshverma3379
    @deepanshverma33792 жыл бұрын

    I am following your website and channel sir for data structures and algorithms. May be I am the luckiest guy to get this worldclass teaching free and hatsoff to your effort sir huge respect for you

  • @Pepcoding

    @Pepcoding

    2 жыл бұрын

    This really means lot .Stay tuned and keep watching. For better experience visit on nados.pepcoding.com

  • @jhanvisaraswat6976
    @jhanvisaraswat69763 жыл бұрын

    Wow, the problem breakdown really helped to understand the question properly.

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    Thankyou beta! I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem. If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @dhawalraturi1160
    @dhawalraturi11602 жыл бұрын

    Very nice explanation sir! Thankyou very much!

  • @VKBMath
    @VKBMath3 жыл бұрын

    I have not seen any teacher who is explaining so much except kj sir of mathematics for jee preparation in kota.I am from IIT Indore

  • @devenderkumar5459
    @devenderkumar54593 жыл бұрын

    always loved the way u teach us sir.......♥

  • @username-tg7if
    @username-tg7if3 жыл бұрын

    great content sir....thank you so much

  • @aashishgoyal1436
    @aashishgoyal14363 жыл бұрын

    Thanks a lot sir. bhut ache se sikhaya .

  • @SHASHANKRUSTAGII
    @SHASHANKRUSTAGII2 жыл бұрын

    Sir kamal ho gya sare questions hai apke pas jo companies m poochte h

  • @shresthjain985
    @shresthjain9853 жыл бұрын

    Amazing explanation!

  • @codewith_ayushluthra5248
    @codewith_ayushluthra5248 Жыл бұрын

    Thanks sir Amazing content .

  • @anthonya880
    @anthonya8803 жыл бұрын

    The quality of the lessons when you are alone is much much better. You are a gifted teacher. I hope someday you replace these videos.

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    I am glad. Keep learning. Keep supporting. Your kind words are the kind of motivation that truly help me in making more and more content. Especially, these days, not everybody is generous with motivating anybody either. It means a lot

  • @yashshvigupta564
    @yashshvigupta5642 жыл бұрын

    thanks sir for such a good explanation

  • @MuSicLiFesong
    @MuSicLiFesong Жыл бұрын

    thank you sir...u explained very well ❤

  • @chetannain4867
    @chetannain4867 Жыл бұрын

    Thank you Sir!

  • @NirmalSilwal
    @NirmalSilwal3 жыл бұрын

    best explanation one can give in this problem, kudos to you. Thank you so much sir.

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    Thankyou beta! I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem. If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @NirmalSilwal

    @NirmalSilwal

    3 жыл бұрын

    @@Pepcoding sure sir

  • @shastriamisha
    @shastriamisha2 жыл бұрын

    Amazing teaching Sir, I wish i had found this channel earlier. Thank you very much.

  • @Pepcoding

    @Pepcoding

    2 жыл бұрын

    We also regret you found us so late. Can you help save some of your friends from this regret? We are dedicated to create top-notch content.

  • @shastriamisha

    @shastriamisha

    2 жыл бұрын

    @@Pepcoding will definitely do

  • @parmarinfotech
    @parmarinfotech2 жыл бұрын

    I love the way you explained visually. Thanks a lot for your efforts. Keep it up. I would like to add one point which make it bit simpler if we try to iterate values from last index. Below solution is written in javascript as I'm not java guy :) const solutionByDP=(s)=>{ const n=s.length; if(n===0) return 0; const dp=Array(n); dp[n]=1; for(let i=n-1; i>=0; i--){ if(s[i]==="0") dp[i]=0; else{ //add previous value for single chart/digit dp[i]=dp[i+1]; //check double digit if(i+1

  • @Chandraprakash-kx4ic
    @Chandraprakash-kx4ic Жыл бұрын

    Thanku very much sirr :)

  • @RitikKumar-bk6pj
    @RitikKumar-bk6pj2 жыл бұрын

    Sir this dp series is very osm and understandable

  • @vesperbeats6673
    @vesperbeats6673 Жыл бұрын

    That is great sir

  • @aryanshaw2462
    @aryanshaw24622 жыл бұрын

    I am a noob in DSA and as a noob i can say that i loved this video and way of explanation and i understood clearly

  • @Pepcoding

    @Pepcoding

    2 жыл бұрын

    Thank you! Cheers! For better experience and well organised content visit on nados.pepcoding.com Don't forget to follow us on Instagram instagram.com/pepcoding/

  • @sudhanshukumar1558
    @sudhanshukumar15583 жыл бұрын

    Great content sir 🙏🙏🙏 loved your explanation

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem. If you like my efforts, I request a review g.page/Pepcoding/review?rc

  • @umber3117
    @umber31174 жыл бұрын

    You are really hardworking and you are doing amazing work. One recommendation please, It would be more helpful if you could do this in recursion.

  • @Pepcoding

    @Pepcoding

    4 жыл бұрын

    beta, DP ko tabulation se karenge. Recursion ki ek bhot fodu 50 questions ki alag playlist aaegi. Usme recursion itna ho jaega ki aap samjhenge kyun mai DP tabulation se pasand karta hun. And maybe, I just got an idea. I will release a separate playlist for all DP questions, where all questions will be done via recursion (memoization)

  • @kanhamishra1630

    @kanhamishra1630

    3 жыл бұрын

    @@Pepcoding yes sir

  • @mickyman753

    @mickyman753

    3 жыл бұрын

    @@Pepcoding sir wo level2 hi hai na tagdi playlist recursion ke liye ,ya koi alag se aaegi

  • @democrats9579
    @democrats95792 жыл бұрын

    Thank You!

  • @tombrady7390
    @tombrady73903 жыл бұрын

    Its fine if she is there as it becomes very abstract for a teacher to teach to a lifeless camera than to a human , it is a bit more easier.

  • @Sarojkumar-yh9uy

    @Sarojkumar-yh9uy

    3 жыл бұрын

    thik hai

  • @ojasdighe991

    @ojasdighe991

    2 жыл бұрын

    @@Sarojkumar-yh9uy chik hai

  • @soumeshnayak4546
    @soumeshnayak4546 Жыл бұрын

    Awesome sir🤩🤩

  • @ashutoshbajpai8498
    @ashutoshbajpai84983 жыл бұрын

    thanks a lot, quite helpful

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    Glad it helped and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @ashwinvarma9349
    @ashwinvarma93493 жыл бұрын

    Sir but how do we identify a dp problem?

  • @akhilsharma9778
    @akhilsharma97783 жыл бұрын

    Well organized content Thanks sir

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    Glad you liked it and If you like the content could you post something on LinkedIn about us? This will help us in reaching out to more people and help a lot of other students as well Something like this Sumeet Malik from Pepcoding is making all his content freely available to the community You can check it out here - www.pepcoding.com/resources / Also, this is the youtube channel - kzread.infoplaylists?view_as=subscriber

  • @faizanwar4843
    @faizanwar48432 жыл бұрын

    Great way of explanation.

  • @Pepcoding

    @Pepcoding

    2 жыл бұрын

    Glad it was helpful! You can also check out nados.pepcoding.com for more such content and Free Resources✌️

  • @Deepusingh-ct6kx
    @Deepusingh-ct6kx4 жыл бұрын

    Nice sir 🥰

  • @speedbreaker5642
    @speedbreaker56422 жыл бұрын

    "00".equals(any_string_variable); It helps in reducing NPE's. Just a programming practice.

  • @ankitkalranoida
    @ankitkalranoida3 жыл бұрын

    Sir really helpful, keep going.

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    Thank you, I will

  • @rahuljain5642

    @rahuljain5642

    3 жыл бұрын

    @@Pepcoding TEST CASE : "06383" or "008834" is not covered :)

  • @rishabhkesarwani5761

    @rishabhkesarwani5761

    3 жыл бұрын

    @@rahuljain5642 question mein diya hua hai , starting mein hamesha non zero hoga!

  • @AJAYKumaryadav-fj2lc
    @AJAYKumaryadav-fj2lc2 жыл бұрын

    Thx u sir for this

  • @Pepcoding

    @Pepcoding

    2 жыл бұрын

    Glad we helped you, for better experience and curated content sign up on nados.io, you can also post your queries on community tab of NADOS.

  • @nipunjindal9505
    @nipunjindal95052 жыл бұрын

    One test case is wrong sir.. I coded the same question on your website and failed a test case. It was for input (90), expected ans was gives as (0) but I don't get how? It should have been (1).. right?

  • @alpishjain1317
    @alpishjain13173 жыл бұрын

    great explanation sir!

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    Glad it was helpful! and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @vikasjindal3791
    @vikasjindal37913 жыл бұрын

    Sir, how will you find count for 130 and 1304

  • @shubhamagarwal9321
    @shubhamagarwal93213 жыл бұрын

    Me after looking at the final code: Sochta hoon ki wo kitne masoom the...kya se kya ho gaye dekhte dekhte😂 Great explanation as always sir😊

  • @shubhammittal4389
    @shubhammittal43892 жыл бұрын

    wonderful explanation by sumeet malik sir

  • @Pepcoding

    @Pepcoding

    2 жыл бұрын

    Keep watching and keep supporting us. And for better experience and well curated content sign up on nados.io and start learning.

  • @kunalsihare5244
    @kunalsihare52443 жыл бұрын

    sir isme last m i-1,i+1

  • @vanshikakapoor85
    @vanshikakapoor852 жыл бұрын

    Amazing

  • @KB-zg8ho
    @KB-zg8ho3 жыл бұрын

    Sir lovely explanation and if possible please make an option of adding questions as bookmarks on your site

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    There is a chrome extension by the name Geeks Assistant by Ronak Sakhuja for this purpose.

  • @vikasjindal3791
    @vikasjindal37913 жыл бұрын

    in case dp[i] = 0; Can't we directly return 0, instead of running the loop?

  • @gouravkrroy3625

    @gouravkrroy3625

    2 жыл бұрын

    i was searching for this comment!!:)

  • @pasitopasito1967
    @pasitopasito19673 жыл бұрын

    It is general suggestion that if you upload video of dp level up question then please make a new playlist that makes easy to learn...and diffrentiable ..thanx to make such a course..

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    Acknowledgement

  • @mollaabbas4695
    @mollaabbas46952 жыл бұрын

    question tho maza agaya sir!!

  • @Pepcoding

    @Pepcoding

    2 жыл бұрын

    Hope you like our explanation.☺️ For better experience and well-organized content visit - nados.pepcoding.com

  • @AshishKumar-tb6go
    @AshishKumar-tb6go3 жыл бұрын

    if 1st character is 0 then we need to return 0 and also if we encounter 00 then we also do the same.

  • @jointroomclasses1466
    @jointroomclasses14662 жыл бұрын

    Hello Sir, You are really explaining each topic in very depth... I'm loving your whole playlist. 😍 I'm just having 2 doubts so far: 1- Where should we take the array of "n" size? and where should we take it off "n+1"? because this is creating a lot of confusion in my mind. 2- How are we deciding ki 0 to 0 is the smaller problem? this can also be called the same for n to n is the problem? And similarly, 0 to n is the bigger problem could also be said, n to 0 is a bigger problem. Please elaborate this a bit, I've tried multiple ways and examples to clear this doubt but it's still there. Thanks in Advance... 🤗

  • @suzanaangboo2448

    @suzanaangboo2448

    Жыл бұрын

    It depends on the problem and what the DP data structure is storing. A simple example of when n+1 would be necessary: let's say the DP array is storing computations where the index represents the length of a string. An array of size n will not have enough space for the case of an empty string (index 0), the case of the entire string (index n), as well as everything between. Size n does not allow indexing beyond n-1, while size n+1 allows indexing at n (which many problems call for). In short if you represent index as a Value then the length of Array should be n+1 otherwise n

  • @ary_21

    @ary_21

    Жыл бұрын

    it depends upon the question example : i am allowed to give you at max 3 rupees what are the possible coins i give you? 0,1,2,3 are the 4 possible answers since 0 was also a possible solution u need a container of size 4 to store all the results similarly in dp we have 2 options a. to create a columns from 1 to n b. to create columns from 0 to n , in this case we use n+1 sized container Lets think about target sum subset , col 3 means can the array elements generate a target of sum 3 , if yes we place true otherwise false In the same problem col 0 means can the array elements generate a target of sum 0 v1={1,2,3} v2={0,4,6} , note that v1 vector cant generate 0 as target so we push(false) but v2 vector can generate 0 so we push(true) i.e 0 is an important case and thus this problem belongs to type b. problem2) count the number of possible outputs generated after decoding a string 123, here col 0=> number of possible outputs that can be formed by picking 0 elemnts from 1 bove string Ans) obviously 0 col1=> number of outputs =1 i.e a this questions belong to type a because 0th col will always be filled by 0 and col 1 is not dependent upon 0th col to get the answer so we omit it completly in both the cases i have assumed empty subset as a solution is not allowed , otherwise v1={1,2,3} can also generate 0 as a target sum via an empty subset. To sum up : we use 0th col in dp array if 1. it generates diff outputs for diff input array or 2. even if it generates the same output , the output is used as a base condition by col 1 or col 2 or any col in the right side Otherwise we omit 0th column. Hope this helps

  • @somyasinghal5935
    @somyasinghal5935 Жыл бұрын

    sir can you please dry run it, cause i can't do it for this very question, I got the concept completely, but can't make a dry run for it

  • @rohitantil9534
    @rohitantil95343 жыл бұрын

    Sir jo qustn hm tabulation se kr rhe h kya hm unn questions ko memoization trick se kr skte h

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    Hanji beta, memoization se aap har recursive question ko kr skte ho. Aur memoization vala part aap logo k liye homework h, vo aap sbko khud krna h.

  • @rakshitdevra7060
    @rakshitdevra70602 жыл бұрын

    sir this dp series is undoubetely the best in india no paid or unpaid course can macth the level of this.

  • @madhavbhutada4611
    @madhavbhutada46112 жыл бұрын

    Great content sir . I have a doubt regarding the above question. We have solved all the cases but not of the type 013 which gives invalid input as we have taken dp[0] = 1 we have already considered it to be correct which cannot always be the case . If you could help me out with this problem that would be great.

  • @dheeraj6142

    @dheeraj6142

    2 жыл бұрын

    Actually this type of case is not given in the question itself and is considered invalid, that's why sir has taken dp[0]=1

  • @AbhishekKumar-md4ul
    @AbhishekKumar-md4ul Жыл бұрын

    why 1-D array, since supply are not unlimited, we should use 2d array right?

  • @ritikgalgate7783
    @ritikgalgate7783 Жыл бұрын

    sir aap itna accha padhaate ho ki doubt hi nhi rahte kya doubt puche??

  • @namrataswain624
    @namrataswain6243 жыл бұрын

    Amazing explanation sir. Waiting for level up dp questions.

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    thank you beta. kal se shuru honge. next 17 days, 10 questions every day. agar aapko content sahi lag rha hai to, please drop us a review www.google.com/maps/place/PepCoding.com/@28.6993713,77.1360927,17z/data=!3m1!4b1!4m7!3m6!1s0x390d03d054d3e717:0x4fd0fdfc3f27ffaf!8m2!3d28.6993666!4d77.1382814!9m1!1b1

  • @namrataswain624

    @namrataswain624

    3 жыл бұрын

    @@Pepcoding Done sir

  • @anjneykumarsingh4461
    @anjneykumarsingh44613 жыл бұрын

    Sir i am adopting your technique feynman, but it take lot of hardwork

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    Keep it up

  • @gopaljaiswal1876
    @gopaljaiswal18763 жыл бұрын

    Sir what if the first charcter is zero ?

  • @ashishgoswami6303
    @ashishgoswami63033 жыл бұрын

    Great

  • @shivanshbajpai4144
    @shivanshbajpai41443 жыл бұрын

    Has anyone run this code in gfg I don't think it works

  • @namangupta7772
    @namangupta77722 жыл бұрын

    if str[0] = 0 then it prints 1 so you have to also add condition to check whether it is zero or non -zero so that dp[0] = 0 or dp[0] = 1

  • @karanveersingh5535

    @karanveersingh5535

    2 жыл бұрын

    U are right 👍

  • @udaysaikumarnookala5431
    @udaysaikumarnookala54313 жыл бұрын

    There should be a small change in the final solution where ever dp[i] = 0 replace it with dp[i] = dp[i-1] and in line 20 change it to dp[i] = (i >= 2 ? dp[i-2]+dp[i-1]: 1 ) rest of the logic is verified and correct

  • @shubhamsood1406

    @shubhamsood1406

    3 жыл бұрын

    Isn't dp[i] = 0 is correct ? bco if number is >26 or =00 then 0 should be added and also dp[i] = (i >= 2 ? dp[i-2] : 1) bcoz we add [i-2] count there.

  • @shreeyagupta8472
    @shreeyagupta84723 жыл бұрын

    in the line dp[i]= i >=2? dp[i-2] : 1 , shouldn't 1 be replaced by dp[i-1]+1 . because we are counting ba and u . Also wouldn't line //19 work for 27 ,28,29 which is undesirable ..

  • @suryanshyadav3423

    @suryanshyadav3423

    3 жыл бұрын

    Line 19 won't work for 27, 28, and 29 because we already stated that the second digit would always be equal to '0'.

  • @shreeyagupta8472

    @shreeyagupta8472

    3 жыл бұрын

    @@suryanshyadav3423 Got it. Thanks!

  • @Komalgupta-gk8ny
    @Komalgupta-gk8ny3 жыл бұрын

    Sumeet sir agar isme hum input 1201234 yeh le na toh ans ana chahiye 3 lekin is code ke hisab se 1 ara hai samaj nhi ara kyuki jabki humne charro case liye hai aur sir jab aap sabse pehle jab dp[0]=1 kare ho lekin agar sabse pehle no 0 hua toh us case ke liye hume condition lagani padegi agar pehle element 0 hai toh 0 warna 1 pr sir plz yeh btado yeh wale input ke liye galat kyu ara ans same yahi code likha hai.thanku in advance

  • @AshokKumar-ot3dz

    @AshokKumar-ot3dz

    3 жыл бұрын

    3 hi aa raha hai answer... 1201234 ke liye... Shayad tumne code likhne mein koi mistake kar di hogi

  • @shouryaxalxo6182

    @shouryaxalxo6182

    3 жыл бұрын

    Are you solving it using c++? If so, then are you using substr function, cause the 2nd parameter of that function is the length of the substring from the position. So you have to write s.substr(i-1,2) and it should work.

  • @harshitmalik7068
    @harshitmalik70682 жыл бұрын

    What if the ending of the string is something like ......."001". At 1, we will be putting dp[i] = dp[i-1] = 0 but isn't that wrong ?

  • @gourishanker9975

    @gourishanker9975

    2 жыл бұрын

    Bro This itself is a wrong string . Because if you have two zeros simultaneously , how you gonna decode it. Suppose I give you a string 11001 . How will you decode it .There is no way of decoding it .So the answer will be zero.

  • @shubhamaggarwal3823
    @shubhamaggarwal38234 жыл бұрын

    sir ji , poora array kyu store karaya , last 2 elements ko store kara kar bhi to kam chal jayega or space bach jayegi

  • @Pepcoding

    @Pepcoding

    4 жыл бұрын

    Bilkul sahi. Mai kai baar optimise nahi karta, khaaskar space. To aap agar better kar sakte hain to jaroor socha karie.

  • @MrPanthershah
    @MrPanthershah2 жыл бұрын

    Code is failing for this case : String Length = 2 and string starts with 0 (e.g. "06") because default value at dp[0] = 1. This needs to be checked if first character is 0 or not.

  • @shubhammittal4389

    @shubhammittal4389

    2 жыл бұрын

    in question constraint is given string can not start with 0 so please read question again

  • @manishgupta9721
    @manishgupta97212 жыл бұрын

    No one can match sumit sir expalnation level....OP sumit sir

  • @gauravsingh4355
    @gauravsingh43553 жыл бұрын

    Ye wala question Include Exclude Method se related nahi hai na sir??? Q ki previous video mein bola tha next 5-6 question same group ke hai.....ye ek dum alag hi method lag rha tha issliye

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    nhi ye uss group ka nahi hai

  • @devanggupta2616
    @devanggupta26162 жыл бұрын

    Why didn't we used 2D array here. Row represented as string and column represented as length of string?

  • @vikashchandra6262
    @vikashchandra62622 жыл бұрын

    Damn 😍🔥🔥

  • @mastersk7440
    @mastersk74403 жыл бұрын

    Why sir do you not provide this content in c++

  • @anjneykumarsingh4461

    @anjneykumarsingh4461

    3 жыл бұрын

    Sir is java developer aur language toh asan h maths algorithm seekho

  • @SagarSharma-uk6rw
    @SagarSharma-uk6rw2 жыл бұрын

    sir the solution is wrong at 26th minute. Example : If the string is "29" , then for {2} -> we will store 1 in 0th index but at 2 index (with your code in video ) we will store 1 at 2nd index which is wrong as 29 >=2 :i-2:1 will evaluate to 1 only.

  • @Chandraprakash-kx4ic
    @Chandraprakash-kx4ic Жыл бұрын

    11:35 sir : koi dikkat apko... (see reaction on mam face)🤣🤣🤣🤣🤣🤣

  • @amanaryan5193
    @amanaryan51933 жыл бұрын

    leetcode decode ways solution: Add up : string may contains leading zeroes. class Solution { public: int numDecodings(string s) { if(s.length()==1){ if(s[0]=='0') return 0; } vector dp(s.size(),0); dp[0]=1; if(s.length()>=2){ if(s[0]=='0') return 0; } for(int i=1;i=2?dp[i-2]:1); else dp[i]=0; } else if(s[i-1]!='0' && s[i]!='0'){ if(stoi(s.substr(i-1,2))=2?dp[i-2]:1); else dp[i]=dp[i-1]; } } return dp[s.length()-1]; } };

  • @architgupta4034
    @architgupta403414 күн бұрын

    1 case left. If str[0] == '0' then dp[0] = 0 else dp[0] =1

  • @souravjha2146
    @souravjha21463 жыл бұрын

    what if initial characters are 0

  • @ms-lk6bw
    @ms-lk6bw2 жыл бұрын

    How to print all the string combinations ?

  • @Pepcoding

    @Pepcoding

    2 жыл бұрын

    For better insight, visit nados.io, post your doubts, community will help you out there.

  • @mdebrahim2164

    @mdebrahim2164

    2 жыл бұрын

    only fo 1 case, remaining case ,you can do same way.

  • @Gargananya
    @Gargananya3 жыл бұрын

    sir dont you think for 00 case, you should break the loop btw great content !! :)

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    Thankyou beta! I’ll go through it once again

  • @Gargananya

    @Gargananya

    3 жыл бұрын

    @@Pepcoding and please correct me if i am doing it wrong

  • @namanmittal9403

    @namanmittal9403

    3 жыл бұрын

    @@Pepcoding and after line no. 22 also we must add a break statement, basically we must break the loop once we get to add 0 to the DP array, I guess.

  • @anubhavgupta4412

    @anubhavgupta4412

    3 жыл бұрын

    @@Pepcoding sir same in the case of target sum subset question agr ek baar bhi j = 10 pr true agaya to break the loop stop filling the dp array ......

  • @varunmodi5608
    @varunmodi56082 жыл бұрын

    Kya ye ek better tareeka hota iss problem ko solve karne ka? for(int i=1;i0) { dp[i]+=dp[i-1]; } if(two>=10 && two2?dp[i-2]:1); } }

  • @Pepcoding

    @Pepcoding

    2 жыл бұрын

    Visit nados.pepcoding.com and sign up to NADOS, for better experience, precisely arranged content and you can also post your query on community tab. Don't forget to follow us on Instagram instagram.com/pepcoding/ Happy Coding!

  • @arpitsohar174
    @arpitsohar1744 жыл бұрын

    Sir, iss question ke test cases mein 21100, 21123 daldijiye. Galat result pe bhi submit horha h.

  • @Pepcoding

    @Pepcoding

    4 жыл бұрын

    Thank you beta. Update kar dunga.

  • @aashishjha3223

    @aashishjha3223

    4 жыл бұрын

    21100 vle ka ans 0 aayega?

  • @varuntaneja1036

    @varuntaneja1036

    3 жыл бұрын

    @@aashishjha3223 haan bhai 0 ayega

  • @sculptandstyle_
    @sculptandstyle_ Жыл бұрын

    2 3 1 akele akele agr rkhe to 3 bna skte h why this case is not considered

  • @rugvedb9842
    @rugvedb98422 жыл бұрын

    Full PRO

  • @ishaankulkarni49
    @ishaankulkarni492 жыл бұрын

    can someone please give the c++ code?? my code is giving wrong answer 🙏🙏😭

  • @Pepcoding

    @Pepcoding

    2 жыл бұрын

    Visit - nados.pepcoding.com and sign up to NADOS. You can ask your doubts on community tab. There are lots of programmers and mentors who can help you out with such doubts. Don't forget to follow us on Instagram instagram.com/pepcoding/

  • @vegitogamingpubg3364
    @vegitogamingpubg33643 жыл бұрын

    Legend says that she is still saying 'chik haa '😂

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    keep motivating, keep learning and keep loving Pepcoding😊

  • @025_basharatnawaz4
    @025_basharatnawaz42 жыл бұрын

    what about the case when str[0] == '0' Sir, I think you missed it.

  • @terminator_363

    @terminator_363

    2 жыл бұрын

    This is an invalid input. A string starting with 0 will not be passed.

  • @Deepusingh-ct6kx
    @Deepusingh-ct6kx4 жыл бұрын

    Sir, please start graph(dfs, bfs) ☺

  • @Pepcoding

    @Pepcoding

    4 жыл бұрын

    bhot jald. bass, 2-4 din mei.

  • @ujjwalsharma6574
    @ujjwalsharma6574 Жыл бұрын

    Please note there is an edge case missing in this if(s.charAt(0)=='0'){ dp[0]=0; }else { dp[0]=1; } if the first character is 0 than dp[0]= 0 else dp[0]=1

  • @ritikgalgate7783

    @ritikgalgate7783

    Жыл бұрын

    the question has stated that 0th index cannot be 0

  • @prashantgupta7631
    @prashantgupta76312 жыл бұрын

    we should use if else for dp[0], it can not we always 1 if s[0]==0 than dp[0] will be 0.

  • @Pepcoding

    @Pepcoding

    2 жыл бұрын

    doubts ke liye yahi content nados.pepcoding.com pe consume karein

  • @abhayrathi284
    @abhayrathi2842 жыл бұрын

    For leetcode add this one case: if(str.charAt(0) == '0'){ return 0; }

  • @Pepcoding

    @Pepcoding

    2 жыл бұрын

    Keep learning. And for better experience, visit nados.io, where you will get well curated content and career opportunities.

  • @bhumikaramchandani9330
    @bhumikaramchandani93302 жыл бұрын

    Str.length() - 1 kyun print kiya instead of str.length() only

  • @shubhagytaswaraj5028

    @shubhagytaswaraj5028

    2 жыл бұрын

    Because here he has taken a dp array of length n(i.e len of string) and according to 0 based indexing , dp[str.length] will go out of bounds.., dp[n-1] will store the number of ways to decode..

  • @bhumikaramchandani4900

    @bhumikaramchandani4900

    2 жыл бұрын

    @@shubhagytaswaraj5028 yeah yeah.. I got that thanks for explaining btw 😊

  • @__RohitDevar
    @__RohitDevar3 жыл бұрын

    Kaise huwa kaise huwa thu(pep coding) itana zaruree kaise huwa. Solved this problem in leetcode ....with out even seeing soln And felt yai mai ho ya koi oor hai ..

  • @Pepcoding

    @Pepcoding

    3 жыл бұрын

    Haha. Keep learning, Keep growing and keep loving Pepcoding!😊