Recursion Google, Amazon Questions: Dice Throw & Letter Combinations of a Phone Number
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
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
Glad you liked it
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
Cannot thank you enough
thank you so much. helped me a lot
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
Thankyou so much pal!!
From where does the final for loop start? You have just given a semi-colon there
You're my only hope Kunal please continue this playlist list. Waiting for more on hash maps, trees, dynamic programming etc 🙏🙏
deepak did you complete all the vedio lectures
@@amansayer4943 Yes
did you got placed now??
@@atharvasarode8057 No reply tells the answer 🤡🤡
@@reverbmusic8444 🤣😅 real
Tears in my eyes man, literally solved without help. Thank You 3000 Kunal🙏🙏🙏
I love how i am consistently improving for my upcoming interview!
I am very lucky to find this channel.
when you have said what to do at 32:00, literally your intuition made me think how to do. thank you kunal kushwaha
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.
Kunal your DSA videos are remarkable! Thank you for this.
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!
This way of solving questions using up and p is lit 🔥💯, Thanks Man! Great Work 🙌🏻
Best Content I ever Seen . this is we needed . we need an approach to solve any question than solving questions : ) . Great Job . Appreciate 🔥
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!
I Cant explain in words , Hatts off to you Kunal !!, Thanks a lot for making this course available for us.
One day I'll learn DSA just bcz of you kunal
Thanks a lot ,I eagerly wait to see your tutorials .Great job ..
Thankyou so much Kunal for this amazing series... ❤️
I used to memorize solution before now I'm learning to build solution . Thanks kunal
The way you make all these so-called complex problems simple is just amazing ❣
It took me three hours but I was able to solve them by myself...best lecture on DSA recursion
Your Explanation is Amazing kunal bhai.. I completed My Civil Engeenering.. Now I am learning coding easily by you😍
wondering!!!!!!! how easily you are able to explain a pattern or question soo nicely....thanks brother
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.
Thank you so much Kunal .just following your course
Nice! I have seen lot of recursion tutorial but all are confusing. I feel this is the best one i find
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 🙂
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!
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 .
I usually don't comment on any CZcams video but i had to appreciate you after watching this class. great job sir🙏
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
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 🙏
Thank you so much for teaching me this pattern! I am so grateful for this channel :)
kunal recursively telling us to go to previous videos is
One of the great mentor I have seen
Please start a bootcamp of python after java . ❤️
Thanks Man! You deserves this comments and appreciation:)
his teaches shows that we are learning from PRO DSA .
Thank you so much Kunal ✨. Your videos are invaluable!
I got confidence after watching and practicing recursion series.
Thanks @Kunal
Wow! You explain so well!!!
Gratitude
You are the greatest, Kunal!
Thanks for teaching not just recursion but also the thought process to aproach and solving the problem
Best recursion course on youtube.
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
These patterns are helping me a lot...Thank you so much for such an amazing lecture
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!
it finally just clicked for me thank you kunal
Thank you for this Kunal!!
I'm solving some challenging problems, which I though I will never be able to, Thank you.
Lets dig in!
You are really a great teacher!
Thanks for all videos kunal sir
Damn the previous videos literally made it easier to understand these questions ⚡
It's just perfect bro
Really awesome Recursion series, explained concepts in easy to follow steps 👍
Glad you think so!
Literally crazyy stufff🤯
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.
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!
Excellent!
bro can u pls share the assignment solution(letter combination)...it will be a great help
can you share the solution?
@@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;
}
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.
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
thanks bro actually i was stuck, can you also help me with previous recursion codes in c++. please
@@umangsrivastava6639 I will help you..
@@rohitchilhorkar8114 please do bro
@@umangsrivastava6639 How can I contact you?
Can you provide your email?
integer + 'a' will also work
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
Awesome explanation
Good Day!
Greetings 🙏👍
Could you why we need i
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]) ?
only due to you I was able to solve dice question on my own.Thank you bro!
Happy to help
@@KunalKushwaha Brother when will you complete the playlist ?
can you share the solution?
yo pls complete the series bro,dont wanna learn trees n graphs from anyone else
You're a legend.
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!
where is he using python bro
@@SudhanshuKumar-xy6xv lol wrong course
@@SudhanshuKumar-xy6xv 🤣
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
In the dice problem, why there is a condition i
wait, if (i
can anyone help me find BST link from Kunal's playlist?
26:20 why is not count value updated to 0 in each function call as count = 0 in the recursive function
13:36. 3 3 ja 🤣🤣🤣and thanks kunal for all this
Great content
precious 🙏
37:00
Is the face needed because anyways we are going to run the loop till target only
have a doubt that instead of count function, can't we just return the size of the ans arrayList?
Hi Kunal,When can we have trees and graphs??
... also waiting for 100K ❤️
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
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
Thanks 👍
thanks for the video
Best!!!
when wil be the dynamic programming is going to start kunal bhai?
Спасибо!
still watching consistently
😀😀😀😀😀
bro please help me with solution for phone pad with the same approach
Video 34 Completed!
Techstartup be like :- ab humare course kaise bikenge
😂😂😂
what's the time complexity of second question??
Sir, do u also share the solution of assignment questions??
great video "value will go from 3 till " 19.04 😂 but anyways very helpful video thanks a lot
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"))
But I have a doubt, why are we considering the variable for face we can directly run the loop from 1 to target.
target gets updated at every recursion call
Can anyone tell the exact code for Letter Combination on Leetcode?
I am still unable to think these complex things. Pls guide
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
sabko ignore maaro
@@KunalKushwaha 🙂🙂yupp
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??????
creating list
Thanks