Compute All Mnemonics For A Phone Number (Recursion/Backtracking Problem)

Поділитися
Вставка
  • Опубліковано 21 гру 2024

КОМЕНТАРІ • 66

  • @BackToBackSWE
    @BackToBackSWE  6 років тому +7

    Table of Contents:
    Video Setup 0:00 - 0:21
    Problem Introduction 0:21 - 2:01
    Walk Through Examples 2:01 - 3:33
    Walking Through The Recursion 3:33 - 7:34
    Time and Space Complexities 7:34 - 12:00
    The Code 12:00 - 16:16
    Wrap Up 16:16 - 17:00
    Conclusion 17:00 - 17:34
    I tried my best. Markers were dry, lighting couldn't be adjust too well since the markers wrote badly on the board (not enough ink). Been sick for the past 3 days. This will suffice for now. Any questions, put them below.

    • @sahilsaluja1504
      @sahilsaluja1504 4 роки тому

      ua-cam.com/video/6m4wHF2JPII/v-deo.html Better and hindi explaination to the problem. Pls support your hindu sher bhai and show some love. why give views to him. watch the best approach on my video and pls get your friends to subscribe to my channel. Your hindu sher needs you......

  • @LetsBeHuman
    @LetsBeHuman 5 років тому +18

    Finally someone is explaining space and time complexities for all problems. If you explain the time and space complexities for all problems, one day I will donate my first month salary after getting new job to your patreon account.

    • @BackToBackSWE
      @BackToBackSWE  5 років тому +16

      hahaha I mean I do this every video . And...no need. Just let me know of the offer, keep the money.

  • @skh551
    @skh551 5 років тому +3

    Although video quality was not very good, but as usual, you draw the recursion tree step by step and then write the code and everything is just crystal clear. Please make more videos on backtracking. I must say this is probably the best channel for understanding lots of difficult programming problems.

  • @voskigolf899
    @voskigolf899 5 років тому +2

    Thanks man good info. I saw this problem almost a month ago and have been stuck trying to solve it. I watched this, n-queens, and backtracking blueprint videos once yesterday. After watching those videos I was able to sit down and solve the problem without having to memorize the solution

  • @SauravKumar-xg4zr
    @SauravKumar-xg4zr 5 років тому +3

    Hey Ben,
    You are a great example of "practice makes a man perfect".
    After seeing your teaching style in the latest video(new one) to this one( old one).

    • @BackToBackSWE
      @BackToBackSWE  5 років тому +1

      hahahaha, im just a dude, not perfect, pretty normal

  • @kiratibhuva63
    @kiratibhuva63 5 років тому +1

    I am learning backtracking currently and after watching many videos, I came here and that's the kind of understanding I needed. Thanks :) Cool stuff...

  • @sanjeevsiva17
    @sanjeevsiva17 5 років тому +2

    underrated channel, keep this going guys

  • @mykolanesov5411
    @mykolanesov5411 3 роки тому

    If you are watching this and don't understand where is the backtracking while it just looks like a simple recursion - that is exactly how it looks like. It's not a backtracking problem. Ben does great videos that helped me a lot but this is not one of them. Sorry :D Keep filming man. You are doing a great job indeed.

  • @CHIchangching
    @CHIchangching 5 років тому +1

    I would like to thank you for making all these hard works videos. If I were you and having no marker to write on the board, I would probably just skip making this video. But you still made it. Keep up good things!

    • @BackToBackSWE
      @BackToBackSWE  5 років тому +3

      Hahahahaha, I remember this video. This was wayyyyyy back. Yeah. That day sucked. Half these videos I didn't wanna make. I didn't wanna make this channel.
      I had to. No one else would do what I envisioned.
      So I'm doing it.

  • @rajiiiv123
    @rajiiiv123 3 роки тому

    I think the space complexity is O(4^n * n) as there are total of 4^n mnemonics each of length n. Let me know if i am wrong.

  • @mhehar3yahoo
    @mhehar3yahoo 5 років тому +5

    Dude you're great. I'm downloading your thought process ;)

  • @minicraft9158
    @minicraft9158 3 роки тому

    what if i use two for loops instead??

  • @Akvn1000
    @Akvn1000 5 років тому +4

    Sir, I just wanted to know how to derive recursive formula for this question. I was unsatisfied with geeksforgeeks explanation. Thanks for making a video on non trivial problems like these.

    • @BackToBackSWE
      @BackToBackSWE  5 років тому +1

      I will cover problems like this here: twitter.com/thebigoguide, it's the site I'm working on

  • @danielpanagio5156
    @danielpanagio5156 5 років тому +2

    This video is fantastic! Thank you very much

  • @zishantareque689
    @zishantareque689 5 років тому +1

    Would an iterative solution be possibly asked for these problems? if so, how will they be solved? As every recursive solution can be done iteratively

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      I'm honestly not sure, I mean consider the state that the recursive frames hold, they cache current choices so iteratively we would have 1 stack variable for the current pending selection and the stack would literally hold what the recursive call stack would hold...current progress, the choice made, etc.
      It's been a while since I did this problem but all that happens when recursion disappears is that state management becomes very tedious.

  • @neharikakhera6411
    @neharikakhera6411 4 роки тому +1

    Very clear explanation!!

  • @alisonfoster7262
    @alisonfoster7262 2 роки тому

    Got a version of this question on an interview today and was able to code it up but could not, for the life of me, figure out the time complexity (*melting emoji face*)

  • @sanketdesai3365
    @sanketdesai3365 6 років тому +2

    Awesome explanation man! You should create more videos like this.

    • @BackToBackSWE
      @BackToBackSWE  6 років тому

      working on it. thanks. you are cool.

  • @adebs
    @adebs 5 років тому +1

    Hi Ben! How does the code know to go from A to B after its found all the permutations for A? I understand how it works visually, but I don't understand how it works in the code.

    • @BackToBackSWE
      @BackToBackSWE  5 років тому +2

      The call stack frame that recursed into A still has the state that B is next. The call stack carries state of the function call. It is an enclosed entity with its own state and behaviour.

    • @adebs
      @adebs 5 років тому +1

      @@BackToBackSWEthat actually makes sense!! thank you so much!!

  • @JyotinderSingh
    @JyotinderSingh 4 роки тому +2

    lovely lovey video! Thanks for introducing the N Queens video as well, really helped me out to watch that before this one. Lovely explanation. Grateful :')

  • @abhimanyu6215
    @abhimanyu6215 6 місяців тому

    Best expiation ever sir.
    Thank you so much for your efforts.

  • @lovetyagi277
    @lovetyagi277 4 роки тому +2

    Great.
    Thanks for the great introduction and for taking discussion so deep in terms of information.
    Great work indeed.
    Helpful 🙏👏👏

  • @doruwyl
    @doruwyl 5 років тому +1

    Maybe I am missing something. I would say that the solution is a DFS solution and not a backtracking solution.
    How I could tell that? Well I don't see the "step back" action (or revert last choice) in the solution.
    Ben, could you clarify my doubts?

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      Yeah this video is old haha. Backtracking: en.wikipedia.org/wiki/Backtracking
      This does not prune pathways of exploration, it is simple recursion

  • @chandrashekharpaatni3223
    @chandrashekharpaatni3223 5 років тому +1

    I was doing code on the same which you have described on the video but there is case where added value need to be removed. so that it will work proper and create all the possible words from the given array. Thanks for sharing your valuable knowledge.
    static void possibleWordsWithMobile(int[] a, String partialString, int index) {
    if (index == a.length) {
    System.out.println(partialString);
    return;
    }
    for (int i = 0; i < mobileAlphaWords[a[index]].length(); i++) {
    partialString += mobileAlphaWords[a[index]].charAt(i);
    possibleWordsWithMobile(a, partialString, index+1);
    partialString = partialString.substring(0, index);
    }
    }

  • @dhruvroytalukdar7942
    @dhruvroytalukdar7942 4 роки тому +1

    thank you sir for your detailed explanation....this is really helpful..

  • @PankajKP
    @PankajKP 5 років тому +2

    You are awesome dude.. where are you from??? country??

  • @HenriqueAbrantesVitoi
    @HenriqueAbrantesVitoi 7 місяців тому

    Is it backtracking or simply a recursion?
    After each sub-problem we are guaranteed that this is the current optimal solution, it's a tail recursion. There is no need to back-off and explore other possibilities at each stack.

  • @mrboyban
    @mrboyban 2 роки тому

    Where is the code?

    • @BackToBackSWE
      @BackToBackSWE  2 роки тому

      Do check out backtobackswe.com/platform/content

  • @viditsharma3929
    @viditsharma3929 3 роки тому

    thank you

  • @chaoschao9432
    @chaoschao9432 5 років тому +2

    Linked to Leetcode 17

    • @BackToBackSWE
      @BackToBackSWE  4 роки тому +1

      I haven't replied to this for a bit, replying to close this out in my "unresponded to comments" feed.

  • @merajahmed4434
    @merajahmed4434 5 років тому +1

    Mardokay is Indian?
    He says "Theek hai".

  • @sujanece99
    @sujanece99 4 роки тому +1

    Thanks! Great explanation.
    I solved the problem using backtracking. The language is Swift (just for information). Can you please let me know the time and space complexities for this solution? Will it be the same as for the recursive solution as you explained in the video or is it different?
    func combinationsHelper(_ mapping: [String: [String]], _ digits: [String], _ index: Int, _ result: inout [String], _ combination: inout [String]) {
    if index == digits.count {
    result.append(combination.joined())
    return
    }
    let elements = mapping[digits[index]]!
    for i in 0..

  • @PiIsRational
    @PiIsRational 4 роки тому +2

    Another great video. I solved this problem using only recursion, but I want to try the backtracking algorithm (before I look at your answer) to see if I got the lessons of the N Queens problem down. My recursive solution is here(gist.github.com/StevenXL/bbb2db93fcc2ecda1fe220169a738f0a). If you don't mind some constructive criticism, I think in this problem you could have been more clear that the reason we are using 4 as our base instead of 3 is that we want to figure out the "worst-case scenario" for our algorithm. Our algorithm does the most work when every digit maps to four characters, hence our base of 4. In my solution, I determined the running time (though not the space complexity) using a recurrence relation, which expanded into the geometric series 4 ^ 1 + 4 ^ 2 + 4 ^ 3 ... 4 ^ n. You'll probably touch upon this in future videos since it is a common bit of math for algorithms. P.S. Keep up the great work. I think a lot of different items that I've been studying are coming together in your videos.

  • @rohitjoshi6335
    @rohitjoshi6335 4 роки тому +1

    Let's Crack FAANG

  • @ogradus
    @ogradus 4 роки тому +1

    You're the best! I'm glad you beat COVID early lol
    while (true) {
    beSafeAndTakeItEasy();
    cout >> "Thanks again!" >> endl;
    }