Get Keypad Combination - Solution | Recursion | Data Structures and Algorithms in JAVA
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 solution of the famous Nokia Keypad question where we are required to find all the possible combinations obtained from certain presses on a keypad as explained in question. For a better understanding of this problem, click here: • Get Keypad Combination...
For a better experience and more exercises, VISIT: www.pepcoding.com/resources/o...
#pepcoding #programming #freeonlinecourses
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
Пікірлер: 201
Ur content gonna change the future of many it engineering aspirants great work ❤️❤️❤️❤️
@Pepcoding
4 жыл бұрын
Thanks a ton
@shubhamsonal5871
3 жыл бұрын
@@Pepcoding Please solve a problem called : rod cutting problem using recursion, here we need to maximise the number of cuts we can make. I am unable to understand the brute force approach of solving this using recursion. Link to the problem is ide.geeksforgeeks.org/ItQt4rQ0ND Please note, I am not expecting the DP solution but just a clarity on the given code. please make a video on this using recursion.
@bikramjitdas7000
3 жыл бұрын
@@shubhamsonal5871 yes sir I also got stuck. And I am learning from your playlist, I have a question sir, How to know I am now ready for thr interview,and also how to apply off campus for product based companies
@gungunsinghal9562
3 жыл бұрын
Yeah..thanks pepcoding
"Submit karne walo ki kvi haar nahi hoti, but, shayad unka code udd jata h kvi kvi" Hilarious..😂😂😂
@Prasoonvarshney16
3 жыл бұрын
lol
@nivealokhande2153
Жыл бұрын
🤣🤣
Sir i did this on my own !... aapne faith se result nikalna sikha diya sir ache se thanks a ton :)
@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
@nikitajaiswal9112
2 жыл бұрын
Mujhse nhi bn paya mene previous questions khud kiye pr ye nhi bn paya Or eske pehle wala question bhi.. Ye question solve krne ke liye kis video ko achhe se dekhna h pepcoding ke any suggestion
Not even a single teacher in KZread aur any another platform clear concept like you cleared in each n every lecture... Hats off sir... 🙏🙏
Iss channel ke aas paas koi aa nahi paega agle 5 saalon tak itna acha flow mein apdaya gya hai ye
@Pepcoding
3 жыл бұрын
Thank You!! Keep watching and share it with your peers
@harshitagnihotri4018
3 ай бұрын
you were right . he is still on top
hahaha 15:19 explanation level OP !! "Idhar baaalti hi khaali h.. But idhar baaalti me magga h.. magge me paani nahi h." I was laughing out loud!! Great explanation btw!! Keep it up
Sir your content is unmatchable. since I started watching your videos, DSA has become so simple. Thanks a ton.
Love your explanation sir, watched your prev videos and did this on my own. Thanks a ton.
The flow of this playlist was so great that,I solved this problem on myown Thnx Sir ,my first recursion problem!!
Simple solution for adding " " in arraylist is that " " will make the size of arraylist as 1 and the inner loop for(String rstr : rres) will run once for every character ( lets say abc for case of integer 2). Now if we did not add " " then the inner loop will never run and hence the size of arraylist will remain zero, final output will always be a zero size empty arraylist.
@Pepcoding
3 жыл бұрын
Correct
@aahanaganjewar9951
3 жыл бұрын
oh i see!
@aahanaganjewar9951
2 жыл бұрын
[""] size = 1 meaning balti mein mugga h mugge mein pani nahi h [] size = 0 meaning balti he khali h
@nivealokhande2153
Жыл бұрын
@@aahanaganjewar9951 when interviewer asks realf life example 🤣
thanks sir, I am able to solve almost all the problem by getting the concept explained in first couple of videos of playlist. I did this problem also before looking at your solution .
You are Doing great work for students like me who belong to a very small village and cannot afford any data structure course.
Sir , Very good explanation to every question. Thanks for providing free content with such excellent explanation.
Very underrated video, this video deserves much more likes and views.
esa content khi doodne se nhi milega salute sir for your effort
Watched on 20 October, 2021 - Thanks for the video.
I understand recursion because of u sir thanks a lot
Your patience level is just amazing
sir.... you are so hardworking... you are a nice teacher... ekdum mast... chill hokar samjhate or wo bhi bhot mast tareeke se.. dil jeet liya sir apnr
@Pepcoding
3 жыл бұрын
Dil ke badle linkedin pe ek post likh do beta ki aisa aisa ek channel mila jispe free content hai. Umeed karunga ki aap sirf video nahi dekhenge, question submit bhi karenge www.pepcoding.com/resources/online-java-foundation
Love your Teaching and your methodology
@15:25 Thank you Sir. Very graphical explanation...baalti me mug hai aur mug me paani nahi not just baalti me paani nahi hai
@Pepcoding
3 жыл бұрын
You are welcome 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 )
Wonderful way of teaching great work done sir
Thank you sir , mai aapke wajah se recursion seekh paaya hoon , nhi to mera pichle 6 months se dimaag kharaab ho rha tha jab bhi mai recursion ke problem dekhta tha...... lekin ab shi se ho jata hai . Thank you for providing free content . Its AWESOME.....
@Pepcoding
3 жыл бұрын
Thank You very much!! It's nice to hear this !! keep watching and share it with your peers
@em_nikhil_007
3 жыл бұрын
@@Pepcoding sure sir i will share you channel . Congratulations for 10K..
Thank you for this explaination, because of you I saved myself from giving up on this recursion problems.
@Pepcoding
2 жыл бұрын
Glad to know that you love our video, for better experience. Visit - nados.pepcoding.com and sign up to NADOS. Don't forget to follow us on Instagram instagram.com/pepcoding/
Thank you so much for this wonderful explaination
Duniya ki har problem ka explanation 2 ki power 0 , 1 hota hai ya 0, ab agar 2 ki power zero 1 sach hai to ye bhi sach hai:) thank you real life jeetu bhaiya :)
@Pepcoding
3 жыл бұрын
:-)
Sir pakka pakka samajh aa Gaya !
You made difficult problem so easy and understandable, thank you sir
@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 )
After thinking for 2 hrs , I finally did the code by myself in c++, since i don't know java, Thank you sir for such type of questions
@Pepcoding
3 жыл бұрын
Keep learning, Keep growing and keep loving Pepcoding!😊
@yashodeepdhas8408
3 жыл бұрын
will u share me the code ?
@yashodeepdhas8408
3 жыл бұрын
please ?
@sukanyamahapatra4742
3 жыл бұрын
@@yashodeepdhas8408 yes okay
@yashodeepdhas8408
3 жыл бұрын
@@sukanyamahapatra4742 thanks and do connect on LinkedIn I have sent you request 😄
You are the best teacher..🙏 Thanks.. beautiful explanation..❤️
@Pepcoding
3 жыл бұрын
It's my pleasure
@Pepcoding
3 жыл бұрын
Glad to know that you liked the content and thank you for appreciating. The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos. So, keep motivating, keep learning and keep loving Pepcoding😊
@nknidhi321
3 жыл бұрын
@@Pepcoding Definitely sir, Prepcoding is the only channel with so much of detailed explanation.. coding se pehle approach, fir code, fir code k saath dry run, heaven.. !! ❤️❤️❤️
best teacher for DSA
Very clear explanation sir, please keep the good work up Advice: at the start of solution video, please advice to watch the question video first and put its link in description, it might be confusing for new comer
@ayushgoel9584
4 жыл бұрын
That is why sir always tell us to solve from portal, where everything is arranged :)
@Pepcoding
4 жыл бұрын
Yes, you are right
@Pepcoding
4 жыл бұрын
Noted
Awesome Explanation.
Wow sir you made recursion a very interesting topic Thank you sir..
@Pepcoding
3 жыл бұрын
Thankyou! If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )
What an explanation... 👏👏
Instead of returning arraylist with empty string, the base case can return the characters of last keystroke: if(str.Length == 1) { List templist = new List(); var tempindex = Convert.ToInt32(str); // last character is the index for kpc var itemKpctemp = keyPadCodes[tempindex]; // get the keypad code for the integer in input string str representing last character var kpccharstemp = itemKpctemp.ToCharArray(); // convert keypad to character array foreach (var tempchars in kpccharstemp) { templist.Add(tempchars.ToString()); // store each character as string into templist and return it to interact with rest of the kpc characters on the way down } return templist; } That way one recursive call is prevented (on the way down) and the base case looks easier to understand. P.S. this is C# implementation
Amazing content on your channel for Recursion & Backtracking. Appreciate your efforts and contribution.
@Pepcoding
3 жыл бұрын
If you like my efforts, I request a review g.page/Pepcoding/review?rc
@dheerajyadav9099
3 жыл бұрын
@@Pepcoding excellent
@kamalnayan5331
2 жыл бұрын
@Pepcoding Rated 5 *
Sir you are the best
Thanks a lot
cyrstal clear explanation
You can use this as base condition which is more easy to explain also: if(str.length() == 1){String keyValues = map.get(str); //using HashMap here. Ex --> {"1", "a,b,c"} String [] arr = keyValues.split(","); return Arrays.asList(arr); }
very nice
balti hi khali hai balti mai mugga hai but mugge mai paani nhi hai xD Best Explanation Sir ji
Sir.. Outstanding video.. Wouldn't it be better to have base case as string.length ==1 and then return array of individual character in that.. With this, we can avoid empty array elem which is weired.
@Pepcoding
3 жыл бұрын
Thankyu beta! And jo aap base case keh rh ho usse dubara analyse kro aur ek bari aache se dry run kr k dekho pura question dubara se. You'll automatically get the answer of your question.
@sachingoyal7443
3 жыл бұрын
@@Pepcoding analyzed.. And found it correct.. Submitted solution on leetcode. It's working fine.
@511-neelbutani9
3 жыл бұрын
@@sachingoyal7443 can you excalty say what you returned ?
Sir you are great
Could you comment on how optimum the solution is . Some comment on time complexity would be great. The content is great though
sir, agar isme array pass ho toh instead of string. ??
It could be better if you explain TC and SC. and thanks for awesome video.
sir jab mres toh har baar new create ho raha haiin,toh purana vaala kaise return ho skta?
you r an inspiring teacher
@Pepcoding
3 жыл бұрын
thank you
You are best
Humne ghabraana nai hai, haar nai manani, Humne sirf Faith Rakhna hai and Faith ko Expectation se connect krna hai.
@Pepcoding
3 жыл бұрын
Correct
Sir it's fine to use this:- String s = arr[Integer.parseInt(String.valueOf(ch))]; For ascii code
why are we not using stringBuilder instead of string as it gives the O(N) complexity when we try to add the strings.
I am the 1000th liker of this wonderful video class.
@Pepcoding
2 жыл бұрын
Thankyou for your support. And for better experience, visit nados.io, where you will get well curated content and career opportunities.
God level explanation!!
@Pepcoding
2 жыл бұрын
Glad it was helpful! For better experience and well organised content sign up on nados.io Don't forget to follow us on Instagram instagram.com/pepcoding/
kya baat hai sir
You are going to be viral in coming months
@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
Sir,do the empty character has ascii value
Dusre to sirf padhate hai,sir feel kra dete hai....💖
@Pepcoding
2 жыл бұрын
Glad that you love our explanation. Visit nados.pepcoding.com and sign up to NADOS, for better experience, precisely arranged content. Don't forget to follow us on Instagram instagram.com/pepcoding/
Thank you so much for this wonderful explaination sir. By the way, What is the complexity of this code ?
@Pepcoding
3 жыл бұрын
You're welcome
@Pepcoding
3 жыл бұрын
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 )
@HarshKumar-nh6be
3 жыл бұрын
number of digits to the power n
thanks bhai
@Pepcoding
2 жыл бұрын
Glad it helped! Keep learning. And for better experience and well organised content visit nados.pepcoding.com
I'm in love !! ❤️
@Pepcoding
3 жыл бұрын
wow, this cheers me up. I am glad we at pepcoding could be of help to you. Keep learning. Also, recommend us to your juniors and peers, they may also benefit
"balti mai magga magge mai pani nhi" wah sir 😅
Sir, if i declare "codes" array in main and pass it to the getKPC(String s, String[] codes) like this in each call... How does it would affect Space Complexity in general?
@Pepcoding
3 жыл бұрын
koi nuksan nahi hoga, same rahegi. pass nahi kia aur har function call mei bnaya tab badhegi
@sukhmansindhi2920
3 жыл бұрын
@@Pepcoding thank you sir.. Because of you I am now able to solve these recursive problems on my own....
Sir, buffer reader is good, or Scanner class for user input in competitive coding? Sir, please reply!!!
@Pepcoding
3 жыл бұрын
buffer reader
great video
@Pepcoding
3 жыл бұрын
Glad you enjoyed it
Sumit bhaiya str length has been given as constraint in the question to uska use kare na
@Pepcoding
4 жыл бұрын
Yes.
sir , level-up course bhi youtube pe ayega?
@Pepcoding
4 жыл бұрын
yes
Thankyou sir 😊
@Pepcoding
3 жыл бұрын
agar aapko content pasand aa rha hai to ek review de dijie please g.page/Pepcoding/review?rc
@kunwaranas24
3 жыл бұрын
@@Pepcoding ji bilkul sir
What is Time complexity?
if we run this code for " " this case the output will be [" "] but the right answer should be [ ], how can i improve this can anybody help.
@utsavgupta746
3 жыл бұрын
Return empty vector krdo aur jab vector recieve kr rhe toh check krlo if mres.size() ==0 phir push krdo usme empty string. I hope u will get it 🙂
@511-neelbutani9
3 жыл бұрын
@@utsavgupta746 bhai kese ?
@Prodcater
2 жыл бұрын
@@511-neelbutani9 in java how to do this?
@harcharansingh1997
Жыл бұрын
@@Prodcater did you find solution
can someone pls share cpp code ?
wrong answer not working on leetcode
sir, it should be pure recurssion ? u used loop ? why ?
@Pepcoding
3 жыл бұрын
yes but loop is used for different purpose
Anyone having java Leetcode solution .1 test case is Failing
Sir web development k coarse bhi aega KZread p??
@Pepcoding
4 жыл бұрын
hanji. poora aur jaldi.
@shubhampokhriyal8491
4 жыл бұрын
Thanks sir kbse aega??
I am looking forward to join ur placement course, how can I approach you?
@Pepcoding
4 жыл бұрын
We will do one around October. Announcement will be don eon the channel.
@NikhilKumar-of5gb
4 жыл бұрын
@@Pepcoding I have sent a msg on pepcoding whatsapp no., Can u PLZZ reply there, I wanted to talk something
One doubt sir, what is the purpose of using static here: 'static String codes' instead of just 'String codes'
@Pepcoding
3 жыл бұрын
beta jo static bnaya wo sare functions mei global variable ki tarah mil jaega.
@hinamankani5319
3 жыл бұрын
@@Pepcoding sir phir 'public' ka kya use hota h 'public static void' me
@letsdoeverythinginoneweek9398
3 жыл бұрын
@@hinamankani5319 likh bhi sakta ha or nahi bhi dono ma chalega vaisa agar class public ha toh public likhna ma koi dikkat nahi ha
it will not give answer for empty string
22:23 han sir mera bhi hua hai bhut baar. XD
@LegitGamer2345
3 жыл бұрын
yeh hota kyu hai mere saath bhi huua hai
leet code soln in cpp class Solution { public: const vector pad = { "" , "" , "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" }; vector letterCombinations(string digits) { if( digits.length() == 0) { vector v= {}; return v; } char c = digits[0]; vector v = letterCombinations(digits.substr(1)); string s = pad[c - '0']; vector temp; if(v.size() == 0) { for(int i=0;i
balti me magga magge me pani nhi hai now , ill remeber
Respect++;
@Pepcoding
2 жыл бұрын
Hope you love the explanation, for better experience and well organised content visit - nados.io
me toh login karne se pehle back jaake code copy kar leta hu...but its really annoying har bar logout ho jata h
Mereko sir kccha wale p hi smjh ajata h age kyunki bdi lmbi hoti h
@Pepcoding
3 жыл бұрын
kya baat hai
balti me magga hai, magge me pani nhi hai. nice example..
@Pepcoding
3 жыл бұрын
Haha..thanks buddy😋 If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )
@manishkumarprasad1911
3 жыл бұрын
SURE. Even I have shared link of pepcoding to our friend circle. thanks a lot to helping us.
My fear to recursion is no more now...all Bec of sumit bhiya.....
@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 our efforts, we request a review g.page/Pepcoding/review?rc You can subscribe to our channel here kzread.infoabout?view_as=subscriber
sir mere c++ code mey brackets and commas nahi aarhe
@Pepcoding
3 жыл бұрын
Beta daal rhe hain
@shreeshree108panchwatidurg3
3 жыл бұрын
@@Pepcoding sir error resolve hogaya aab ! Thank you
@shreshthdimri5685
3 жыл бұрын
Can you share your code
@tanyachhabra5537
2 жыл бұрын
please share your code
@shreeshree108panchwatidurg3
2 жыл бұрын
@@tanyachhabra5537 I've already shared in the previous comment.
*Code in python for reference* def kpc(arr: list, s: str) -> list: if len(s) == 0: return " " first = int(s[0]) remainingKpc = kpc(arr,s[1:]) result = [] for letter in arr[first]: for i in remainingKpc: result.append(letter+i) return result arr = [".;", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tu", "vwx", "yz"] print(kpc(arr,"123"))
Sir khud se nhi soch pa rhe hai question samghane pe samgh aa jata hai
@Pepcoding
3 жыл бұрын
beta foundation mei chinta na karo. level2 dsa tak thinking ban jaegi
12:40
Koi cpp code share kardo plz 🥺
@shreeshree108panchwatidurg3
3 жыл бұрын
krdia bhai.
@DreamfulGal
2 жыл бұрын
@@shreeshree108panchwatidurg3 mujhe bhi plzz
Leetcode problem solution: class Solution { private static String[] codes=new String []{"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; public List letterCombinations(String digits) { if(digits.length()==0){ List bans=new ArrayList(); // bans.add(""+codes[0]); return bans; } return solve(digits); } public List solve(String digits) { if(digits.length()==0){ List bans=new ArrayList(); bans.add(""); return bans; } char ch=digits.charAt(0); String ros=digits.substring(1); List res=solve(ros); List ans=new ArrayList(); String codesforch=codes[ch-'0']; for(int i=0;i
without looking into solution i am not able to solve problems
@tejaskadam1889
Жыл бұрын
started watching from first video of recursion and then able to solve it on my own
Anyone submitted this on leetcode?
13.34 ye kya ghatiya bat kar rahe ho😂 nice
@Pepcoding
3 жыл бұрын
Hahah..ignore that beta😋
Kch nhi ka kuch toh kuch hi hota h (basecase)
@Pepcoding
3 жыл бұрын
Haha
Balti hi khali hai.......balti me mugga hai pr mugge me paani nhi hai.....Hilarious 😂
@Pepcoding
2 жыл бұрын
Hahahaa! For much better experience check out :- nados.pepcoding.com
230 likes 1 dislike
@Pepcoding
3 жыл бұрын
Need more support from you people as this will help us in reaching out to more people and help a lot of other students as well