Leetcode Decode Ways || Intuition + Code + Explanation

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ก.ย. 2024
  • A message containing letters from A-Z can be encoded into numbers using the following mapping:
    'A' - "1"
    'B' - "2"
    ...
    'Z' - "26"
    To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, "11106" can be mapped into:
    "AAJF" with the grouping (1 1 10 6)
    "KJF" with the grouping (11 10 6)
    Note that the grouping (1 11 06) is invalid because "06" cannot be mapped into 'F' since "6" is different from "06".
    Given a string s containing only digits, return the number of ways to decode it.
    The answer is guaranteed to fit in a 32-bit integer.
    Example 1:
    Input: s = "12"
    Output: 2
    Explanation: "12" could be decoded as "AB" (1 2) or "L" (12).

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

  • @vishnuvardhanreddy4841
    @vishnuvardhanreddy4841 ปีที่แล้ว +9

    Mam thank you so much your dp lectures are better than many paid courses.
    U r explanation is so simple and easy to understand 😊😊

  • @VinodMuda
    @VinodMuda 2 ปีที่แล้ว +4

    Nice explanation! Thank you.
    Modified your code(Java) for constant space:
    class Solution {

    public int numDecodings(String s) {
    if(s.isEmpty() || s.charAt(0) == '0') return 0;
    int twoStepsBack = 1;
    int oneStepsBack = 1;
    for(int i = 2; i = '0' && currentChar

  • @keerthana1216
    @keerthana1216 ปีที่แล้ว +1

    Clear explanation,thank you. Also your videos are very crisp and clear ,please make more vidoes,finding quite helpful.

  • @user-tx8zz9xc1y
    @user-tx8zz9xc1y ปีที่แล้ว +1

    Good explanation with different cases

  • @AbdulRehman-ui3nj
    @AbdulRehman-ui3nj 9 หลายเดือนก่อน

    I paused the video at 18:39 to subscribe your channel, thanks for the easy explanation

  • @SHANMUKHASHARMA-s6h
    @SHANMUKHASHARMA-s6h ปีที่แล้ว +3

    Very Well Explained Thank you very much

  • @sakshamgupta304
    @sakshamgupta304 ปีที่แล้ว +2

    Hi @code with Alisha,
    it was such a nice explanation, you efforts were visible in video. However there was a cut in video when you just started tabulation part and then suddenly you lowered your voice, was that because you were recording at night ?.
    haha 😁, if that was so, that was such a cute moment 🤣.

  • @nivedithabaskaran1669
    @nivedithabaskaran1669 2 ปีที่แล้ว +4

    This was such a clear explanation video. Thank you!

  • @TheElevatedGuy
    @TheElevatedGuy 2 ปีที่แล้ว +1

    Clear & Nice explanation!
    Thank you very much ma'am!

  • @biswajitsaha6773
    @biswajitsaha6773 ปีที่แล้ว +1

    Great explanation ma'am, but I think there is a small mistake in it, we can decode "110" in 1 way only (1,10), not 2 ways [21:30]
    1,1,0 is not a valid decoding

  • @shashankpal8888
    @shashankpal8888 3 ปีที่แล้ว +3

    Hey, Can you make a video, how your coding journey start? Where to start? Which platform to do first?

  • @pankajchadda1780
    @pankajchadda1780 ปีที่แล้ว +1

    Awesome explanation 😁 Thank you..

  • @himanshupandey9303
    @himanshupandey9303 3 ปีที่แล้ว +2

    There was a movavi editor plus banner which flashed in intervals in the video.

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

    very useful... thank you

  • @shyren_more
    @shyren_more ปีที่แล้ว +1

    great explanation, thanks

  • @smile8510
    @smile8510 2 ปีที่แล้ว

    awesome explanantion
    just solved it after getting the intuition

  • @heenamittal8621
    @heenamittal8621 2 ปีที่แล้ว +1

    Excellent Explaination !! Thanks !:)

  • @095udaykiran6
    @095udaykiran6 ปีที่แล้ว

    Nice Explaination ,Thank You mam 🙏

  • @bikkichoudhary8565
    @bikkichoudhary8565 ปีที่แล้ว

    Bahut mast samjhate ho aap didi😃

  • @aakashgoswami2356
    @aakashgoswami2356 2 ปีที่แล้ว +1

    why you have taken previous two state i.e dp[i] += dp[i-2] . why dp[i-2] ? And why you have take dp[0] = 1;

  • @pranjalshinde1586
    @pranjalshinde1586 2 ปีที่แล้ว +1

    getting memory limit exceeded while using recursion + memoization

  • @beinghappy9223
    @beinghappy9223 ปีที่แล้ว

    Amazing explanation didi

  • @lalitagarwal9155
    @lalitagarwal9155 ปีที่แล้ว

    Ma'am please tell that can I solve this question using BFS or not?
    I write a code myself using queue for BFS but that's running only for few cases so please tell..

  • @josephcs1235
    @josephcs1235 ปีที่แล้ว

    Great video

  • @shivanshgupta1509
    @shivanshgupta1509 2 ปีที่แล้ว +1

    ThankYou mam!!!

  • @raj_kundalia
    @raj_kundalia ปีที่แล้ว

    You mentioned that you'd tell about why dp[0] = 1. Could you explain that, please?

    • @tanusharma0801
      @tanusharma0801 9 หลายเดือนก่อน

      In simpler terms, when you have an empty string (length 0), there is exactly one way to decode it, and that is by doing nothing. So, dp[0] is set to 1 to represent this one way.

  • @barathnatarajan8566
    @barathnatarajan8566 2 ปีที่แล้ว

    Thank you

  • @vishalagarwal9392
    @vishalagarwal9392 ปีที่แล้ว

    except striver , no youtuber can write recursive solution by themselves

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

      why are you thinkinng like this man ??? 😂😂

  • @jayasatwik1046
    @jayasatwik1046 ปีที่แล้ว

    class Solution {
    public:
    int numDecodings(string s) {
    int i,n=s.length();
    if(s.length()==0||s[0]=='0')
    return 0;
    vectordp(n+1,0);
    dp[0]=1;
    dp[1]=1;

    for(i=2;i='1'&&s[i-1]='0'&&s[i-1]

  • @malkeetsapien4852
    @malkeetsapien4852 2 ปีที่แล้ว

    🙌🏻

  • @ramashishrural
    @ramashishrural ปีที่แล้ว

    Great work 👏 check your LinkedIn request 👏

  • @vikaspeddinti52
    @vikaspeddinti52 2 ปีที่แล้ว +1

    great explanation thanks 😊