Get Keypad Combination - Solution | Recursion | Data Structures and Algorithms in JAVA
Vložit
- čas přidán 24. 07. 2020
- 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
Ur content gonna change the future of many it engineering aspirants great work ❤️❤️❤️❤️
Thanks a ton
@@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.
@@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
Yeah..thanks pepcoding
"Submit karne walo ki kvi haar nahi hoti, but, shayad unka code udd jata h kvi kvi" Hilarious..😂😂😂
lol
🤣🤣
Sir i did this on my own !... aapne faith se result nikalna sikha diya sir ache se thanks a ton :)
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
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 CZcams 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
Thank You!! Keep watching and share it with your peers
you were right . he is still on top
Love your explanation sir, watched your prev videos and did this on my own. Thanks a ton.
Sir your content is unmatchable. since I started watching your videos, DSA has become so simple. 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.
Correct
oh i see!
[""] size = 1 meaning balti mein mugga h mugge mein pani nahi h
[] size = 0 meaning balti he khali h
@@aahanaganjewar9951 when interviewer asks realf life example 🤣
Sir , Very good explanation to every question. Thanks for providing free content with such excellent explanation.
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 .
Watched on 20 October, 2021 - Thanks for the video.
You are Doing great work for students like me who belong to a very small village and cannot afford any data structure course.
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
Very underrated video, this video deserves much more likes and views.
I understand recursion because of u sir thanks a lot
Your patience level is just amazing
Love your Teaching and your methodology
esa content khi doodne se nhi milega salute sir for your effort
Wonderful way of teaching great work done sir
Thank you so much for this wonderful explaination
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
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
Sir pakka pakka samajh aa Gaya !
@15:25 Thank you Sir. Very graphical explanation...baalti me mug hai aur mug me paani nahi not just baalti me paani nahi hai
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 )
Awesome Explanation.
best teacher for DSA
What an explanation... 👏👏
Thank you for this explaination, because of you I saved myself from giving up on this recursion problems.
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/
You made difficult problem so easy and understandable, thank you sir
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 )
Wow sir you made recursion a very interesting topic
Thank you sir..
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 )
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 :)
:-)
Sir you are the best
cyrstal clear explanation
Thanks a lot
You are the best teacher..🙏 Thanks.. beautiful explanation..❤️
It's my pleasure
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😊
@@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.. !! ❤️❤️❤️
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.....
Thank You very much!! It's nice to hear this !! keep watching and share it with your peers
@@Pepcoding sure sir i will share you channel . Congratulations for 10K..
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
you r an inspiring teacher
thank you
Sir you are great
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
That is why sir always tell us to solve from portal, where everything is arranged :)
Yes, you are right
Noted
Amazing content on your channel for Recursion & Backtracking. Appreciate your efforts and contribution.
If you like my efforts, I request a review
g.page/Pepcoding/review?rc
@@Pepcoding excellent
@Pepcoding Rated 5 *
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
Keep learning, Keep growing and keep loving Pepcoding!😊
will u share me the code ?
please ?
@@yashodeepdhas8408 yes okay
@@sukanyamahapatra4742 thanks and do connect on LinkedIn I have sent you request 😄
God level explanation!!
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/
very nice
You are best
Could you comment on how optimum the solution is . Some comment on time complexity would be great. The content is great though
It could be better if you explain TC and SC. and thanks for awesome video.
I am the 1000th liker of this wonderful video class.
Thankyou for your support.
And for better experience, visit nados.io, where you will get well curated content and career opportunities.
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);
}
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.
kya baat hai sir
sir, agar isme array pass ho toh instead of string. ??
Sir,do the empty character has ascii value
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.
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.
@@Pepcoding analyzed.. And found it correct.. Submitted solution on leetcode. It's working fine.
@@sachingoyal7443 can you excalty say what you returned ?
sir jab mres toh har baar new create ho raha haiin,toh purana vaala kaise return ho skta?
I'm in love !! ❤️
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
thanks bhai
Glad it helped!
Keep learning.
And for better experience and well organised content visit nados.pepcoding.com
balti hi khali hai
balti mai mugga hai but mugge mai paani nhi hai xD
Best Explanation Sir ji
You are going to be viral in coming months
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
Thank you so much for this wonderful explaination sir. By the way, What is the complexity of this code ?
You're welcome
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 )
number of digits to the power n
What is Time complexity?
Sir, buffer reader is good, or Scanner class for user input in competitive coding?
Sir, please reply!!!
buffer reader
great video
Glad you enjoyed it
Thankyou sir 😊
agar aapko content pasand aa rha hai to ek review de dijie please
g.page/Pepcoding/review?rc
@@Pepcoding ji bilkul sir
Humne ghabraana nai hai, haar nai manani, Humne sirf Faith Rakhna hai and Faith ko Expectation se connect krna hai.
Correct
Sumit bhaiya str length has been given as constraint in the question to uska use kare na
Yes.
Dusre to sirf padhate hai,sir feel kra dete hai....💖
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/
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?
koi nuksan nahi hoga, same rahegi. pass nahi kia aur har function call mei bnaya tab badhegi
@@Pepcoding thank you sir.. Because of you I am now able to solve these recursive problems on my own....
wrong answer not working on leetcode
sir , level-up course bhi youtube pe ayega?
yes
it will not give answer for empty string
"balti mai magga magge mai pani nhi" wah sir 😅
can someone pls share cpp code ?
Anyone having java Leetcode solution .1 test case is Failing
sir, it should be pure recurssion ? u used loop ? why ?
yes but loop is used for different purpose
me toh login karne se pehle back jaake code copy kar leta hu...but its really annoying har bar logout ho jata h
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.
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 🙂
@@utsavgupta746 bhai kese ?
@@511-neelbutani9 in java how to do this?
@@Prodcater did you find solution
Sir web development k coarse bhi aega CZcams p??
hanji. poora aur jaldi.
Thanks sir kbse aega??
One doubt sir, what is the purpose of using static here: 'static String codes' instead of just 'String codes'
beta jo static bnaya wo sare functions mei global variable ki tarah mil jaega.
@@Pepcoding sir phir 'public' ka kya use hota h 'public static void' me
@@hinamankani5319 likh bhi sakta ha or nahi bhi dono ma chalega
vaisa agar class public ha toh public likhna ma koi dikkat nahi ha
I am looking forward to join ur placement course, how can I approach you?
We will do one around October. Announcement will be don eon the channel.
@@Pepcoding I have sent a msg on pepcoding whatsapp no., Can u PLZZ reply there, I wanted to talk something
Mereko sir kccha wale p hi smjh ajata h age kyunki bdi lmbi hoti h
kya baat hai
balti me magga magge me pani nhi hai now , ill remeber
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 < string > v = letterCombinations(digits.substr(1));
string s = pad[c - '0'];
vector < string > temp;
if(v.size() == 0)
{
for(int i=0;i
*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"))
Respect++;
Hope you love the explanation, for better experience and well organised content visit - nados.io
22:23 han sir mera bhi hua hai bhut baar. XD
yeh hota kyu hai mere saath bhi huua hai
Sir khud se nhi soch pa rhe hai question samghane pe samgh aa jata hai
beta foundation mei chinta na karo. level2 dsa tak thinking ban jaegi
My fear to recursion is no more now...all Bec of sumit bhiya.....
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
czcams.com/users/Pepcodingabout?view_as=subscriber
Anyone submitted this on leetcode?
balti me magga hai, magge me pani nhi hai. nice example..
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 )
SURE. Even I have shared link of pepcoding to our friend circle. thanks a lot to helping us.
sir mere c++ code mey brackets and commas nahi aarhe
Beta daal rhe hain
@@Pepcoding sir error resolve hogaya aab ! Thank you
Can you share your code
please share your code
@@tanyachhabra5537 I've already shared in the previous comment.
12:40
Koi cpp code share kardo plz 🥺
krdia bhai.
@@shreeshree108panchwatidurg3 mujhe bhi plzz
without looking into solution i am not able to solve problems
started watching from first video of recursion and then able to solve it on my own
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
Kch nhi ka kuch toh kuch hi hota h (basecase)
Haha
Balti hi khali hai.......balti me mugga hai pr mugge me paani nhi hai.....Hilarious 😂
Hahahaa! For much better experience check out :- nados.pepcoding.com
13.34 ye kya ghatiya bat kar rahe ho😂 nice
Hahah..ignore that beta😋
230 likes 1 dislike
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