Recursion Google, Amazon Questions: Dice Throw & Letter Combinations of a Phone Number

Sdílet
Vložit
  • čas přidán 21. 07. 2024
  • In this video we cover some important questions on #recursion being asked in companies like Google and Amazon. Not only that, we also look at how to approach such problems, the thought process and come up with a solution.
    LeetCode problems:
    - Number of Dice Rolls With Target Sum
    - Letter Combinations of a Phone Number
    Take part in the learning in public initiative! Share your learnings on LinkedIn and Twitter with #DSAwithKunal & don't forget to tag us!
    👉 Resources
    - Join Replit: join.replit.com/kunal-kushwaha
    - Complete Java DSA playlist: • Java + DSA + Interview...
    - Code, Assignments, & Notes: github.com/kunal-kushwaha/DSA...
    ➡️ Connect with me: kunalkushwaha.com
    =========================================
    Timestamps:
    00:00 Introduction
    01:38 Q1 : Letter Combinations of a Phone Number
    16:41 Code for Q1
    20:41 Returning Q1 output as an ArrayList
    24:58 Returning the count
    27:09 Q2 : Number of Dice Rolls with Target Sum
    32:40 Code for Q2
    34:25 Returning Q2 output as an ArrayList
    36:18 Dice with custom number of faces
    37:50 Outro
    #placement #dsa #interviews

Komentáře • 218

  • @kanyapandey
    @kanyapandey Před 2 lety +151

    Literally nobody has ever taught the way to abstract our thought process by applying Unprocessed & Processed approach for solving subset questions
    Thanks a million Kunal 🙏🙏🙏
    Shoutout to DSA course with Kunal

  • @deepaksolanki1972
    @deepaksolanki1972 Před 2 lety +51

    Requires modification in the calculation of mapping phone-pad numbers to characters. As per Leetcode, 7 and 9 has 4 chars, so the value of i in the for-loop changes.
    public static List solve(String ans, String ip) {

    if(ip.isEmpty()) {
    ArrayList list = new ArrayList();
    list.add(ans);
    return list;
    }

    int digit = ip.charAt(0) - '0';
    int i=(digit-2)*3;
    if(digit > 7) {
    i+=1;
    }
    int len = i+3;
    if(digit == 7 || digit == 9) {
    len+=1;
    }

    ArrayList list = new ArrayList();

    for(; i

    • @siddhantmeshram4092
      @siddhantmeshram4092 Před 2 lety +1

      Cannot thank you enough

    • @JOBFERNANDEZBCD
      @JOBFERNANDEZBCD Před rokem +1

      thank you so much. helped me a lot

    • @akhilpathak1348
      @akhilpathak1348 Před rokem +6

      Just add one edge case for digits.length()==0 , like this
      if(digits.length()==0){
      ArrayList str = new ArrayList();
      return str;
      }
      ** this edge case will be added in the main method**
      I was stuck because of this so thought of adding here for future reference XD

    • @anirudhchakravarty6373
      @anirudhchakravarty6373 Před rokem

      Thankyou so much pal!!

    • @prasaddd77
      @prasaddd77 Před 11 měsíci

      From where does the final for loop start? You have just given a semi-colon there

  • @deepakjanardhanan7394
    @deepakjanardhanan7394 Před rokem +49

    You're my only hope Kunal please continue this playlist list. Waiting for more on hash maps, trees, dynamic programming etc 🙏🙏

  • @ichigolameeeee2423
    @ichigolameeeee2423 Před rokem +7

    Tears in my eyes man, literally solved without help. Thank You 3000 Kunal🙏🙏🙏

  • @determinator4491
    @determinator4491 Před 2 lety +2

    I love how i am consistently improving for my upcoming interview!
    I am very lucky to find this channel.

  • @santhosh7042
    @santhosh7042 Před 2 lety +4

    when you have said what to do at 32:00, literally your intuition made me think how to do. thank you kunal kushwaha

  • @user-kt2uu9qt8l
    @user-kt2uu9qt8l Před rokem +4

    Kunal, I owe you a debt of gratitude. Before your guidance, I never thought I could solve a recursive problem on my own. Your method of teaching us how to approach and find solutions was exceptional. Thank you for empowering me with the skills and confidence to tackle these challenges.

  • @advaitbajaj4241
    @advaitbajaj4241 Před 2 lety +2

    Kunal your DSA videos are remarkable! Thank you for this.

  • @Tomharry910
    @Tomharry910 Před rokem +1

    I was very frustrated with recursion and had given up on coding. Your recursion series has given me exemplary clarity, rekindled my hope and brought me back to coding again. Thank you so much!

  • @pratikmundokar2381
    @pratikmundokar2381 Před 2 lety +4

    This way of solving questions using up and p is lit 🔥💯, Thanks Man! Great Work 🙌🏻

  • @brainglitch
    @brainglitch Před 2 lety +6

    Best Content I ever Seen . this is we needed . we need an approach to solve any question than solving questions : ) . Great Job . Appreciate 🔥

  • @kartikmehta17
    @kartikmehta17 Před rokem +1

    Wow! I am following your recursion playlist and till now, I am able to solve these two problems on my on without looking your solution at first. Never though this gonna happen so fast!

  • @dipakingle6629
    @dipakingle6629 Před 2 lety +2

    I Cant explain in words , Hatts off to you Kunal !!, Thanks a lot for making this course available for us.

  • @San-ix7ki
    @San-ix7ki Před 2 lety +18

    One day I'll learn DSA just bcz of you kunal

  • @mohammedf7147
    @mohammedf7147 Před 2 lety +3

    Thanks a lot ,I eagerly wait to see your tutorials .Great job ..

  • @anchit1237
    @anchit1237 Před 2 lety +7

    Thankyou so much Kunal for this amazing series... ❤️

  • @nitin9042
    @nitin9042 Před 2 lety +3

    I used to memorize solution before now I'm learning to build solution . Thanks kunal

  • @shreyasharma1625
    @shreyasharma1625 Před 2 lety +3

    The way you make all these so-called complex problems simple is just amazing ❣

  • @anitasahoo8418
    @anitasahoo8418 Před 10 měsíci

    It took me three hours but I was able to solve them by myself...best lecture on DSA recursion

  • @JP-bj1fx
    @JP-bj1fx Před 2 lety

    Your Explanation is Amazing kunal bhai.. I completed My Civil Engeenering.. Now I am learning coding easily by you😍

  • @SaiSumanthKovuru
    @SaiSumanthKovuru Před 9 měsíci

    wondering!!!!!!! how easily you are able to explain a pattern or question soo nicely....thanks brother

  • @edukondalugumma3753
    @edukondalugumma3753 Před 2 lety

    Hey Kunal, U are rockstar man. Literally i became fan of you. i subscribed and liked your videos.
    from today onwards i just like to follow you. You are so great.... God bless you.

  • @jonukutirahul3326
    @jonukutirahul3326 Před 2 lety +2

    Thank you so much Kunal .just following your course

  • @abhishekkumarsingh7352
    @abhishekkumarsingh7352 Před 7 měsíci

    Nice! I have seen lot of recursion tutorial but all are confusing. I feel this is the best one i find

  • @jamespeterson7824
    @jamespeterson7824 Před 2 lety

    Solving the question by understanding the pattern makes it easy to solve...Good thought process and recursion is being made easy with kunal...thanks Kunal 🙂

  • @navnav1819
    @navnav1819 Před 4 měsíci

    Kunal another amazing video! I was able to modify the code for the phone question and get a accepted submission on leetcode as well! Keep up the great work!

  • @amansayer4943
    @amansayer4943 Před rokem

    guys lets complete the recursive tree of dice problem .thank you kunal you left that tree at the half . i did it and it solved my lot of doubts .

  • @sakshibhagat4806
    @sakshibhagat4806 Před rokem +1

    I usually don't comment on any CZcams video but i had to appreciate you after watching this class. great job sir🙏

  • @sudhabeliver
    @sudhabeliver Před 2 lety +3

    Even a paid courses wont cover this detail.. Really liked the pattern you have taught.. Yay! I got the intuition to solve recursion problems.. Thanks Kunal.. Waiting for more videos on trees and graphs

  • @aakashyadav9117
    @aakashyadav9117 Před rokem

    please make more videos I'm waiting just to learn from you , your teaching skill is amazing bro i have not found any other youtuber explaining technique like this , they all just jump to solution.but you show us how to think how to solve problems not directly jump to solution . very very thanks to you 🙏

  • @amruthaa5876
    @amruthaa5876 Před 2 lety

    Thank you so much for teaching me this pattern! I am so grateful for this channel :)

  • @sofiyarao815
    @sofiyarao815 Před 2 lety +1

    kunal recursively telling us to go to previous videos is

  • @harshavardhangulla4058
    @harshavardhangulla4058 Před 2 lety +8

    One of the great mentor I have seen
    Please start a bootcamp of python after java . ❤️

  • @pratikmundokar2381
    @pratikmundokar2381 Před 2 lety +1

    Thanks Man! You deserves this comments and appreciation:)

  • @codingonly6680
    @codingonly6680 Před 2 lety +3

    his teaches shows that we are learning from PRO DSA .

  • @tolulopemalomo8922
    @tolulopemalomo8922 Před rokem

    Thank you so much Kunal ✨. Your videos are invaluable!

  • @shubhamyeole2881
    @shubhamyeole2881 Před rokem

    I got confidence after watching and practicing recursion series.
    Thanks @Kunal

  • @mrrishiraj88
    @mrrishiraj88 Před 2 lety

    Wow! You explain so well!!!
    Gratitude

  • @gamaleri7
    @gamaleri7 Před 8 měsíci

    You are the greatest, Kunal!

  • @advrakshachaudhari3699
    @advrakshachaudhari3699 Před 9 měsíci

    Thanks for teaching not just recursion but also the thought process to aproach and solving the problem

  • @kirtishghosh8950
    @kirtishghosh8950 Před 2 lety

    Best recursion course on youtube.

  • @tanubaghel5204
    @tanubaghel5204 Před rokem

    I am able to solve this combination question bt myself which i was believing i will never be able to solve by myself i just can't express my happiness thanks kunal

  • @manasagorle
    @manasagorle Před 3 měsíci

    These patterns are helping me a lot...Thank you so much for such an amazing lecture

  • @_MrThief_
    @_MrThief_ Před 10 měsíci +4

    everything cool but in original leetcode theres no every letter start from *3 bcs 7 is "pqrs", and 9 is "wxyz". I did the simillar job like you but with using additional list in constructor.Thanks for good videos!

  • @felixboachieyiadom4457

    it finally just clicked for me thank you kunal

  • @annabatman9010
    @annabatman9010 Před rokem

    Thank you for this Kunal!!

  • @chinmaiveera2105
    @chinmaiveera2105 Před 2 lety

    I'm solving some challenging problems, which I though I will never be able to, Thank you.

  • @tusharpapnai2907
    @tusharpapnai2907 Před 2 lety +1

    Lets dig in!

  • @rohitchilhorkar8114
    @rohitchilhorkar8114 Před 2 lety

    You are really a great teacher!

  • @ibrahim-lf5he
    @ibrahim-lf5he Před 2 lety

    Thanks for all videos kunal sir

  • @sujalsamai6459
    @sujalsamai6459 Před 2 lety

    Damn the previous videos literally made it easier to understand these questions ⚡

  • @chinmaychaudhari4143
    @chinmaychaudhari4143 Před 2 lety +2

    It's just perfect bro

  • @apoorvabhadauria3024
    @apoorvabhadauria3024 Před 10 měsíci

    Really awesome Recursion series, explained concepts in easy to follow steps 👍

  • @prajwalruke
    @prajwalruke Před 9 měsíci

    Literally crazyy stufff🤯

  • @vasujhawar.6987
    @vasujhawar.6987 Před 2 lety

    thank you man, for all the quality content. Thank you for this video. Please start your patreon or something, I want to donate you for the good cause.

  • @Gnaneshh
    @Gnaneshh Před 2 lety +3

    I was able to solve this problem even without watching the solution. All the previous recursion videos taught me how to do this.Thanks a ton!

    • @KunalKushwaha
      @KunalKushwaha  Před 2 lety +4

      Excellent!

    • @yogeshsikanderpuriya7417
      @yogeshsikanderpuriya7417 Před 2 lety +1

      bro can u pls share the assignment solution(letter combination)...it will be a great help

    • @yashthakur6081
      @yashthakur6081 Před 9 měsíci

      can you share the solution?

    • @blurryface160
      @blurryface160 Před 9 měsíci

      @@yashthakur6081 public static char[] map(char ch){
      HashMap map = new HashMap();
      map.put('2',new char[]{'a','b','c'});
      map.put('3',new char[]{'d','e','f'});
      map.put('4',new char[]{'g','h','i'});
      map.put('5',new char[]{'j','k','l'});
      map.put('6',new char[]{'m','n','o'});
      map.put('7',new char[]{'p','q','r','s'});
      map.put('8',new char[]{'t','u','v'});
      map.put('9',new char[]{'w','x','y','z'});
      return map.get(ch);
      }
      public static List letterCombinations(String up,String p) {
      if(up.isEmpty()){
      List temp = new ArrayList();
      temp.add(p);
      return temp;
      }
      char []arr = map(up.charAt(0));
      List ans = new ArrayList();
      //You can use normal for loop instead of for each
      for (char c : arr) {
      List ansFromBelowCalls = letterCombinations(up.substring(1), p + c);
      ans.addAll(ansFromBelowCalls);
      }
      return ans;
      }

  • @pradiptasarma4867
    @pradiptasarma4867 Před 2 lety +2

    This question isn't talking about the keys being pressed multiple times. It is talking about T9, where you press the keys, once, and it forms a word that is possible from a preloaded dictionary.

  • @rohitchilhorkar8114
    @rohitchilhorkar8114 Před 2 lety +11

    At 33:35 , For coding in C++,
    Must use dice(p + to_string(i), target-1)
    to string will help you to convert int to char

  • @code2287
    @code2287 Před rokem

    This is an amazing tutorial, but no way from the simple subset problems you solve this dice and letters problem 😂😂😂 but am glad I've watched this cause this solution opened the road to many more problems.. p/up is just an amazing concept

  • @sourabhkothari7014
    @sourabhkothari7014 Před 2 lety

    Awesome explanation

  • @mrrishiraj88
    @mrrishiraj88 Před 2 lety +1

    Good Day!
    Greetings 🙏👍

  • @nishanthsunkara1160
    @nishanthsunkara1160 Před 6 měsíci

    Could you why we need i

  • @DnyaneshPise
    @DnyaneshPise Před 2 měsíci +1

    In Q.2 29:45 How you think that we should take 4 in unprocess and not the some data(given data i.e. [1,2,3,4,5,6]) ?

  • @Gurjeetsingh-ks5dv
    @Gurjeetsingh-ks5dv Před 2 lety

    only due to you I was able to solve dice question on my own.Thank you bro!

  • @Rajdweep
    @Rajdweep Před 2 lety +1

    yo pls complete the series bro,dont wanna learn trees n graphs from anyone else

  • @SagarBisen-kt8ex
    @SagarBisen-kt8ex Před 4 měsíci

    You're a legend.

  • @aditya__exe
    @aditya__exe Před 2 lety +18

    Before this course, I thought python is more beginner friendly. Anyone can teach solving a problem but it requires skills to teach how to approach a problem!

  • @DevanshuAugusty
    @DevanshuAugusty Před rokem +1

    in LEETCODE 1st question topic is showing backtracking . But you have done it with recursion ..so is your solution good for an interview?..also what's it time complexity

  • @jcchandru96
    @jcchandru96 Před 8 měsíci

    In the dice problem, why there is a condition i

  • @pranaychoubey829
    @pranaychoubey829 Před 2 lety

    wait, if (i

  • @_ia_wotblitz1400
    @_ia_wotblitz1400 Před 2 lety

    can anyone help me find BST link from Kunal's playlist?

  • @absingh773
    @absingh773 Před měsícem

    26:20 why is not count value updated to 0 in each function call as count = 0 in the recursive function

  • @01utpalraj95
    @01utpalraj95 Před 2 lety +1

    13:36. 3 3 ja 🤣🤣🤣and thanks kunal for all this

  • @akshaykumar-wd8jc
    @akshaykumar-wd8jc Před 2 lety

    Great content

  • @dineshmadduru7043
    @dineshmadduru7043 Před měsícem

    precious 🙏

  • @gowtham9153
    @gowtham9153 Před 7 měsíci

    37:00
    Is the face needed because anyways we are going to run the loop till target only

  • @vinuthnareddy3601
    @vinuthnareddy3601 Před 9 měsíci

    have a doubt that instead of count function, can't we just return the size of the ans arrayList?

  • @sathyammedia6553
    @sathyammedia6553 Před 2 lety +1

    Hi Kunal,When can we have trees and graphs??

  • @ffbad3129
    @ffbad3129 Před 2 lety

    ... also waiting for 100K ❤️

  • @nalamanuraag802
    @nalamanuraag802 Před 4 měsíci

    video is really good
    Just a heads up
    In the actual question, there are no alphabets for 1 and also for 7 and 9, there are 4 letters instead of 3, make sure you modify the code accordingly

  • @aminefourati1258
    @aminefourati1258 Před 10 měsíci +2

    Here is a recipe for these combinatorial algorithms:
    1/ recursion with two main arguments results(starts off empty) and choices
    2/ in each level of the recursion call the choices argument is decremented
    3/when the choices length or value becomes 0, the value for the result argument is a valid result ( add it to the global results or return it)
    4/the problem specific algorithm wil be on how to populate the result argument and decrement the choices argument for each recursive call,
    and the number of calls for each level can be either fixed or variable

  • @harshjaiswal1634
    @harshjaiswal1634 Před 2 lety +1

    Thanks 👍

  • @maddymadhu
    @maddymadhu Před 10 měsíci

    thanks for the video

  • @samruddhighodake223
    @samruddhighodake223 Před 2 lety

    Best!!!

  • @FaizShaikh-dt8wp
    @FaizShaikh-dt8wp Před rokem

    when wil be the dynamic programming is going to start kunal bhai?

  • @ElizabethOlamisan-nh3xr
    @ElizabethOlamisan-nh3xr Před rokem +2

    Спасибо!

  • @rudram4534
    @rudram4534 Před 2 lety +1

    still watching consistently
    😀😀😀😀😀

  • @mageshwaran3321
    @mageshwaran3321 Před rokem

    bro please help me with solution for phone pad with the same approach

  • @itshari5489
    @itshari5489 Před 11 měsíci

    Video 34 Completed!

  • @suyashkumar8840
    @suyashkumar8840 Před 2 lety +18

    Techstartup be like :- ab humare course kaise bikenge
    😂😂😂

  • @anujmaurya6145
    @anujmaurya6145 Před 2 lety

    what's the time complexity of second question??

  • @yashverma685
    @yashverma685 Před 5 měsíci

    Sir, do u also share the solution of assignment questions??

  • @ssu1782
    @ssu1782 Před rokem

    great video "value will go from 3 till " 19.04 😂 but anyways very helpful video thanks a lot

  • @ninadvirkar4129
    @ninadvirkar4129 Před rokem +3

    The implementation for the first question requires a little modification as in the leetcode problem, letters start from 2 & not from 1. Also numbers 7 & 9 have 4 letters. This can be done by using a dictionary easily. I have implemented in JS
    getLetterCombinations = function (p, up) {
    if (up == "") {
    res.push(p)
    return
    }
    let digit = parseInt(up.charAt(0))
    let data = charArray[digit]
    for (let i = 0; i < data.length; i++) {
    getLetterCombinations(p + data[i], up.substring(1))
    }
    }
    var letterCombinations = function (digits) {
    charArray = { 2: "abc", 3: "def", 4: "ghi", 5: "jkl", 6: "mno", 7: "pqrs", 8: "tuv", 9: "wxyz" }
    res = []
    getLetterCombinations("", digits);
    res = res.filter((el) => el != "")
    return res;
    };
    console.log(letterCombinations("23"))

  • @soumyadeeppaul2175
    @soumyadeeppaul2175 Před 2 lety +1

    But I have a doubt, why are we considering the variable for face we can directly run the loop from 1 to target.

  • @anmolverma075
    @anmolverma075 Před rokem

    Can anyone tell the exact code for Letter Combination on Leetcode?

  • @codingwithaddy155
    @codingwithaddy155 Před rokem +2

    I am still unable to think these complex things. Pls guide

  • @haha44261
    @haha44261 Před 2 lety +1

    sir aap jaise padhate hai, usse mai aap ka fan ho gaya hu and usse badh ke mai dsa ka ........
    1 more video to complete the recurssion playlist....
    mai 2 weeks se yahi padh raha hu.... kisi ko kheta hu ki abhi bhi recurssion hi padh raha hu......sabb haste hai......ki time waste karr raha hi......itna time kon padhata hai recurssion.....but i know ......whats going on.......
    thanks

  • @aniruddhakotal1534
    @aniruddhakotal1534 Před rokem

    Can you also tell which one is more efficient, using void return in recursion or using return list type and creating list inside the recursion??????

  • @alpeshnikumbh718
    @alpeshnikumbh718 Před 2 lety

    Thanks