Word Pattern -(Amazon, MakeMyTrip, Microsoft) : Explanation ➕ Live Coding

  Рет қаралды 4,754

codestorywithMIK

codestorywithMIK

Күн бұрын

This is the 3rd Video of our Hash Map/Set Playlist.
In this video we will try to solve a very good problem "Word Pattern".
Problem Name : Word Pattern
Company Tags : Amazon, MakeMyTrip, Microsoft
My solutions on Github : github.com/MAZ...
Leetcode Link : leetcode.com/p...
My GitHub Repo for interview preparation : github.com/MAZ...
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
#interviewpreparation #interview_ds_algo #hinglish

Пікірлер: 44
@sarathkumardunga5240
@sarathkumardunga5240 Жыл бұрын
Happy new year Bhaiya❤.. I am sure ki i am gonna learn a lot in this year too. One of the best thing that happened in Last year is that I randomly found this amazing channel in Demeber. U have a unique way of explaining things.Plss keep continuing the good work. Hope this content reaches many more this year.Looking forward for other videos
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thank you so so so much Sarath. Your comment made my day. Good way to start my year. Thanks a lot. And yeah, let’s rock this year and bring out the coder within us 💪💪💪💪
@dayashankarlakhotia4943
@dayashankarlakhotia4943 Жыл бұрын
Class solution { Public boolean word pattern *string pattern, string s){ string arr[]=s.split(" "); if(pattern. length!=array. length)return false; Mapmap=Hash map(); for(int i=0;i< pattern. length; i++){ char ch=pattern. charAt(i); boolean contains key= map. contains key(ch); if(map .contains value(arr[i])&&!contains key)return false if(contains key&& !map.get(ch).equal (arr[i])) return false else map .put(ch,arr[i]); } return true } };
@souravjoshi2293
@souravjoshi2293 Жыл бұрын
Thanks a lot man. I have taken a resolution to solve at least one Qn every day this year. Thanks to you for the motivation
@codestorywithMIK
@codestorywithMIK Жыл бұрын
That’s the spirit 💪❤️
@riteshhhhh_01
@riteshhhhh_01 3 ай бұрын
It is more similar to L205 and in this question why leetcode us "Bijection" it means the combination of injection and subjection 😢
@arunsharma4792
@arunsharma4792 Жыл бұрын
Sir i am not able to remember solution of previously solved question . After 3 days i forget everything what i did in that question what to do ??
@sarathkumardunga5240
@sarathkumardunga5240 Жыл бұрын
Try to go about a problem from the scratch in a logical and sequential manner. Dont try to replicate the solution that u had learnt. Try to implement in your own way from the experience u have gained. keep practicing.. u can see the progress.
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Hi Arun, The problem you mentioned is faced by everyone. Me also The only thing we do to atleast fight this problem is to never stop solving In worst case, solve atleast one problem a day And try solving random Qn. It helps your brain to recollect more that from which Algo/DS it can be solved. Trust me, people code for years and still they have this issue. Because that's how it is. The important thing is BE CONSISTENT It will give you a sense of confidence that you are doing everyday and it will play a very important role for your future.
@sounishnath513
@sounishnath513 Жыл бұрын
I was stuck because i only focus using string spit by space and Map but few cases not passed😢
@codestorywithMIK
@codestorywithMIK Жыл бұрын
No worries Sounish. It’s totally fine to get stuck. If it taught you something, then we didn’t loose anything right 💪😊 I usually never underestimate Easy Tagged Qns. Because 1) They help me to increase speed 2) For Practice , it’s good 3) Try multiple approaches 4) Some Easy are very very good and worth a try.
@piyushacharya7696
@piyushacharya7696 Жыл бұрын
Loved it bro.😎😎 I wrote this shitty code and came here to learn a better and optimised approach. Always love your approach bhai. Now it's time to grow your channel🔥 If possible update the channel banner and the logo.😁😁 class Solution { public: vector splitWords(string sentence) { string temp; vector arr; stringstream ss(sentence); // convert sentence to words // taking each word and putting it into a vector. while (ss >> temp) { arr.push_back(temp); } return arr; } // tc : O(3n) // not the very optimal code. // since it is of "easy" category so not bothering much. bool wordPattern(string pattern, string s) { int patlen = pattern.size(); vector words = splitWords(s); // since each char must associate with each word so diff len then return false. if (words.size() != patlen) return false; unordered_map map; unordered_map map2; // char -> word. for (int i = 0; i < words.size(); i++) { char key = pattern[i]; string word = words[i]; auto it = map.find(key); // if it does not exists. if (it == map.end()) { map[key] = word; } else { // if the key already exists. if (it->second != word) return false; } } // word -> char for (int i = 0; i < words.size(); i++) { string key = words[i]; char val = pattern[i]; auto it = map2.find(key); // if it does not exists. if (it == map2.end()) { map2[key] = val; } else { // if the key already exists. if (it->second != val) return false; } } // if there are all words the same then also using the two map concept helps. /* example: a b b a dog dog dog dog In map 1: a -> dog b -> dog In map 2: dog -> a/b which is handled. but simply using the one map does not work in this case. */ if (map.size() != map2.size()) return false; return true; } };
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thanks a lot Piyush. And Yes, i will changing the logo and name of my channel may be today or tomorrow EOD Thanks always for your valuable suggestions ❤️❤️❤️❤️
@piyushacharya7696
@piyushacharya7696 Жыл бұрын
@@codestorywithMIK Yeah and if possible do not add underscore to the channel name as it does not look any good.😅😅
@codestorywithMIK
@codestorywithMIK Жыл бұрын
I totally agree. I will remove underscore. Thanks a lot ❤️❤️❤️
@alokgautam02
@alokgautam02 Жыл бұрын
Hoping to get same quality videos from you this year also !
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Sure thing Alok ❤️❤️❤️
@prajwalshaw9217
@prajwalshaw9217 11 ай бұрын
Can anyone tell me why this code is not working...it is passing 30 cases out of 42 cases on lc. The similar code is working for the problem isomorphic strings on lc. class Solution { public: bool wordPattern(string pattern, string s) { unordered_mapmp; unordered_mapused; vectortemp; int cnt=0; for(int i=0;i
@Anurag-fk3op
@Anurag-fk3op 5 ай бұрын
At 8:06 what I did was else { // If the word doesn't exist in map char c = pattern[i]; // Current character in pattern // Check if the character is already mapped to any other word for (auto it : mp) { if (it.second == c) return false; } Time complexity kya hoga ??
@prajwalshaw9217
@prajwalshaw9217 11 ай бұрын
What is the time complexity of approach 1?
@chitranshjain9714
@chitranshjain9714 Ай бұрын
class Solution { public: bool wordPattern(string pattern, string s) { stringstream ss(s); string token; vector tokens; while (getline(ss, token, ' ')) { tokens.push_back(token); } if (pattern.length() != tokens.size()) { return false; } unordered_map mpp; unordered_set st; for (int i = 0; i < pattern.length(); i++) { char ch = pattern[i]; if (mpp.find(tokens[i]) == mpp.end() && st.find(ch) != st.end()) { return false; } else if (mpp.find(tokens[i]) != mpp.end()) { if (mpp[tokens[i]] != ch) { return false; } } mpp[tokens[i]] = ch; st.insert(ch); } return 1; } };
@DevOpskagyaan
@DevOpskagyaan 8 ай бұрын
Legend
@danishsaifi1038
@danishsaifi1038 Жыл бұрын
Nice name for the channel.
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thanks a lot ❤️❤️❤️
@gautamarora6556
@gautamarora6556 Жыл бұрын
@@codestorywithMIK What was the old name of your channel ?
@codestorywithMIK
@codestorywithMIK Жыл бұрын
interview_DS_Algo
@udaytewary3809
@udaytewary3809 Жыл бұрын
Really thankyou bhaiya your awesome and I am really lucky that I found your channel. Solved the question but only able to pass 31/37 test cases so came here to watch your solution and you always rock and teaches us new thing and for me l learnt about stringstream And also one thing bhaiya in your third approach in the if condition outside the loop I think there is no need to write i!=n because i!= n says that countToken is also not equal to n and I also have checked that it is working fine and passed all the test cases
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thanks a lot Uday. And yes you are right for i!=n part Thank you so much Uday for pointing this out
@cj-nr5ni
@cj-nr5ni Жыл бұрын
Great teaching skills … hopin for lld /hld …may be too much to ask .. 😅 nice playlist
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thanks a lot. Soon will plan HLD and LLD
@pritishpattnaik4674
@pritishpattnaik4674 Жыл бұрын
So nice approach , I learnt another approach My approach : vector strToVec(string s){ s += ' '; vector ans; string temp = ""; for (auto x : s){ if (x == ' '){ ans.push_back(temp); temp.clear(); } else temp.push_back(x); } return ans; } bool wordPattern(string pattern, string s) { vector str = strToVec(s); map mp1; for (int i=0 ; i
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Awesome. Thanks a lot ❤️❤️❤️
@nagmakhan3165
@nagmakhan3165 Жыл бұрын
Thanks a lot So much to learn from this
@HolidayHaven-qf3ym
@HolidayHaven-qf3ym Жыл бұрын
Happy new year! Hope aapki help se meri DSA ki journey acchi ho!
@codestorywithMIK
@codestorywithMIK Жыл бұрын
💪💪❤️❤️
@wearevacationuncoverers
@wearevacationuncoverers Жыл бұрын
Great teaching skills
@manishv.8167
@manishv.8167 Жыл бұрын
Hi , Today again you miss to upload the concept video , I was waiting for it ...
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Hi Manish, Will upload tomorrow as today had some tight schedule of other works.
@manishv.8167
@manishv.8167 Жыл бұрын
@@codestorywithMIK ok no issues...🥰
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thanks for understanding. I will try to put more than 1 videos.
@abhinavkumar1356
@abhinavkumar1356 Жыл бұрын
thanks brother
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thanks a lot for watching Abhinav ❤️❤️❤️
@sarathkumardunga5240
@sarathkumardunga5240 Жыл бұрын
For someone who want to solve the question with above logic without using stringstream function class Solution { public: bool wordPattern(string pattern, string s) { int wordCount = 0; int l = s.length(); for(int i = 0; i= 'a' && it
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thanks a lot
An Unknown Ending💪
00:49
ISSEI / いっせい
Рет қаралды 57 МЛН
Nastya and balloon challenge
00:23
Nastya
Рет қаралды 70 МЛН
Spongebob ate Patrick 😱 #meme #spongebob #gmod
00:15
Mr. LoLo
Рет қаралды 19 МЛН
Word Pattern - Leetcode 290 - Python
9:23
NeetCode
Рет қаралды 38 М.
Determine if Two Strings Are Close | Intuition |  Google | Leetcode 1657
24:23
Concatenated Words | Simple Story | META | Leetcode 472
23:17
codestorywithMIK
Рет қаралды 6 М.
Top 50 OOPS C# Interview Questions - .NET
3:05:33
Interview Happy
Рет қаралды 147 М.
Hands-On Power BI Tutorial 📊Beginner to Pro [Full Course] ⚡
3:05:45
Pragmatic Works
Рет қаралды 2,2 МЛН
An Unknown Ending💪
00:49
ISSEI / いっせい
Рет қаралды 57 МЛН