Restore IP Addresses | Recursive Tree | Diagram | META | Leetcode 93
This is the 12th Video of our Strings Playlist.
In this video we will try to solve another very good and popular problem "Restore IP Addresses | Recursive Tree | Diagram | META | Leetcode 93".
Share your learnings on LinkedIn, Twitter (X), Instagram, Facebook(Meta) with the hashtag #codestorywithmik & feel free to tag me.
Problem Name : Restore IP Addresses
Company Tags : META
My solutions on Github : github.com/MAZHARMIK/Intervie...
Leetcode Link : leetcode.com/problems/restore...
My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
0:00 - Intro
0:32 - Understanding Qn
2:35 - Intuition Building
4:47 - Tree Recursive Diagram
17:35 - Interesting Fact
19:19 - Story To Code
29:00 - Time Complexity
32:30 - Live Coding from Story
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
#interviewpreparation #interview_ds_algo #hinglish
Пікірлер: 69
what an explanation👏
I urge everyone to watch full ads in his videos and not skip it...This guy deserves this!
@codestorywithMIK
Жыл бұрын
That’s overwhelming. I want to thank you from the bottom of my heart. That’s very kind ❤️
@nagmakhan3165
Жыл бұрын
True
@souravjoshi2293
Жыл бұрын
Seriously man. I am really gonna do that for this guy. He deserves it.
@user-qo6vg5jb6y
Жыл бұрын
me using adblocker
Finally wait is over
Lovely Explanation...Next level Expalnation....maza hii aagya...
great explanation, huge respect man seriously 👍 keep posting such videos daily and also imp questions from imp topics and interview perspective
this channel is really underrated.... your explanations are crazy good.... thanks for such great contents ❤❤
Crisp and perfect. Thanks a lot for the recursive tree explanation and dry run
Learned alot of new things from this video, thankyou so much 🥺. You always made everything so ezz...
nice explanation
Wonderful explanation
Man you are just awesome. I just saw you crossed 2k subscribers. Congratulations and soon you will reach 1M trust me
Your explanation is really good bro . Keep bringing such videos
@codestorywithMIK
10 ай бұрын
Thank you so much 😇🙏
Mannn!!!🙇🏻♀️🙇🏻♀️ You're the best 🔥🔥🔥
@codestorywithMIK
3 ай бұрын
🙏🙏❤️❤️😇😇
Congratulations for 2K, Wish you many more in future.👏👏👏
you literally made it really easy !!
you are superbbbb.
God Level explanation
He is back 🔥
Best best bhai keep going👍
Thanks a lot
Bestest explanation😇
@codestorywithMIK
Жыл бұрын
Thank you Anshika 😇
Dope 🔥
lit
very helpful!! can you please make a vedio on constraints analysis .(how to take help from constraints in solving questions)
@codestorywithMIK
Жыл бұрын
Thanks Deepa. I have planned to make a video on that too soon. Thanks for watching 😇
Java Solution as per above Approach: class Solution { int n; List result; public boolean valid(String s) { if(s.charAt(0)=='0') return false; if(Integer.parseInt(s)>255)return false; return true; } public void solve(String s,int i,int parts,String cur) { if(parts>4) return; if(parts==4 && i==n) { //remove the dot result.add(cur.substring(0,cur.length()-1)); return; } if(i+1
Really thankyou bhaiya your explanation helped a lot at first I was not able to even approach the problem but after listening to you for few minutes I began to understand the problem and for that really thankyou bhaiya I will be always great full to you One thing wanted to ask you if this type of question came in online interview then what should we do face that type of situation ?
@codestorywithMIK
Жыл бұрын
Thanks a lot Uday During interviews they generally help also , hints are given if you need But it’s important that you atleast share your thoughts out loud
if (parts>4 ) return ; this condition should be added na otherwise it'll call recursion unnecessarily even when we crossed 4Parts
@codestorywithMIK
Жыл бұрын
Yep you can add it too. Good one 👍🏻
god 🛐🛐
You're awesome. But, Please post videos in English, so that it reaches to wider audience.
@codestorywithMIK
Жыл бұрын
Soon I will try to add subtitles. 😇 And make another video in english too
If possible end me Java ka code v ek baar dikha diya karo, baki you teach really good. Congratulations for 2k
@codestorywithMIK
Жыл бұрын
Sure ❤️
Nice approach & Solution If you don't mind can you make 1 video on explaining recursion? Like how generally Recursion are used in leetcode programs, how to think on problems solving from that perspective.. As watching the video I got the hint you will be using recursion but calling recursion 3 times with different parameters etc TBH its hard to trace the calls inside brain n think from that perspective I have started watching this channel start of 2023 I see you release video daily .. It will be tough for you to manage your day IF YOU CAN CREATE VIDEO Then only DO or else its whole fine no issues Thanks Mik 😊
@codestorywithMIK
Жыл бұрын
Hi Akshay, I am soon planning to create playlists on these topics also from scratch. I will just be ok break next month for 3 weeks for travelling, then i will be back again. And definitely i will create videos on what you want. Thanks for watching ❤️❤️❤️
@akshayzade9761
Жыл бұрын
@@codestorywithMIK - Thanks a lot for your efforts and yaa enjoy your days very well We are not running out 😄Your channel has different uniqueness of "Story To Code" Which makes peeps like me to understand easy You are killing the leetcode discussion section.. Keep it up mate 👍
@codestorywithMIK
Жыл бұрын
Thanks a lot 😇❤️
Bro how do u figure out so many things to solve a prob. I am not able to do that 😢 between congrats for 2k bro u deserve more 🔥
@codestorywithMIK
Жыл бұрын
Thank you so much. And regarding approaches, I always believe in making story first. And trust me, with time, it will come to you too. Keep practicing
Java code using for-loop-recursion & regex : ``` class Solution { public List restoreIpAddresses(String s) { List result = new ArrayList(); int N= s.length(); if (N>12) return result; //empty List solve(s, 0, N, new StringBuilder(), 0, result); return result; } public void solve(String s, int idx, int N, StringBuilder ipSoFar, int octetCount, List result) { // defining : base or termination condition if ( octetCount == 4 && idx == N ) { String validIP = ipSoFar.substring(0, ipSoFar.length()-1);//removes trailing delimeter '.' result.add(validIP); return; } // exploring different considerations : max 3 possible at each stage for(int r=idx+1; r
❤ Ye kal ke question jaisa hua na bhaiya? Ki ham backtracking karre har step pe, ki lenge ya nahi lenge string ko, agar valid hai to append karenge warna nahi
@codestorywithMIK
Жыл бұрын
Yep, you can call it backtracking too.
Itni sari conditions sochna ....fir usko Code me convert krna kaise kr lete ho aap ....ho hi ni pata mujhse ye jitna bhi khud se likhne ka try kr lu .... 😥😭
@codestorywithMIK
Жыл бұрын
Trust me, keep practicing and it will come soon. Never stop 💪
@shashwats9273
Жыл бұрын
@@codestorywithMIK Ok bhaiya 🥰❤
Bro why on passing string curr by reference in solve() and isValid() gives an error? I am new to c++ so I didn't get it.
@codestorywithMIK
Жыл бұрын
Actually this is this will give error because, you are trying to pass s.substr() which will be of type std::__cxx11::basic_string to &str which is of type std::__cxx11::string& Both are of different type. So, whenever you pass anything by reference, make sure you evaluate the substr (or any operation) and save it in a variable and then pass it. For example : #include using namespace std; void check(string &str) { cout
@piyushacharya7696
Жыл бұрын
@@codestorywithMIK Bro thanks a lot for describing it so properly even in the comment section. May you get millions of subscribers 💪. 🐐 of DSA explanation.
@codestorywithMIK
Жыл бұрын
Thanks a lot Shrijal. Glad it helped ❤️
Please don't pause the graph concept playlist and complete it soon, so that we can start with other concept like dp,tree ,etc
@codestorywithMIK
Жыл бұрын
Yep Coming tomorrow
Need Help Can anyone tell me where am i wrong class Solution { public: bool isValid(string st){ if(st[0] == '0' || stoi(st) 255) return false; // leading 0 in 2 or 3 size parts AND range check return true; } void solve(string &s, int index, int &n, vector &answer, string ans, int parts){ if(index == n && parts == 4){ ans.pop_back(); // removing last dot . answer.push_back(ans); } if(index+1
We started index from 0 na So why we are using indx+1
@codestorywithMIK
Жыл бұрын
In C++ substr(idx, length) It includes the current element at idx too. For example : s = “abc” idx = 1 I want to take length of 2 substring s.substr(idx, 2) It will take “bc” i.e. start at idx = 1 And from here take 2 length i.e. “bc” so , idx+2 = 1+2
@twi4458
Жыл бұрын
@@codestorywithMIK Thanks for clearification bhaiya, I had the same doubt.
please help it is showing illeagal character class Solution { public List restoreIpAddresses(String s) { List ans = new ArrayList(); if(s.length() > 12){ return ans; } int n = s.length(); String p = ""; helper(p,s,ans,0,0,n); return ans; } static void helper(String p,String s,List ans,int parts,int index,int n){ if(index == n && parts == 4){ ans.remove(ans.size()-1); ans.add(p); return; } if(index+1
code fat jane ka matlab?
@codestorywithMIK
Жыл бұрын
It means “error ajaega” Code fatna is like a slang used in corporate 😅
@oqant0424
Жыл бұрын
@@codestorywithMIK ok😅
My approach: Only 3 options are possible when we are at an index i of str 1. Only option is to take the char at index i. 2. Only option is to put a dot. 3. Exploring both above options class Solution: def f(self,i,n,temp,result,s,last,dotcount): if dotcount >3: return if i == n: if dotcount == 3: result.append(temp) return if last == "":#only_option_is_to_take_the_current_character self.f(i+1,n,temp+s[i],result,s,last+s[i],dotcount) elif last == '0' or int(last+s[i])>255: #only_option_is_to_put_a_dot self.f(i,n,temp+'.',result,s,"",dotcount+1) else:#exploring_both_options_(taking_current_char_and_putting_dot) self.f(i+1,n,temp+s[i],result,s,last+s[i],dotcount) self.f(i,n,temp+'.',result,s,"",dotcount+1) def restoreIpAddresses(self, s: str) -> List[str]: slen = len(s) result = [] if slen>12: return result self.f(0,slen,"",result,s,"",0) return result