Prefix and Suffix Search | Live Coding with Explanation | Leetcode - 745

  Рет қаралды 9,939

Algorithms Made Easy

Algorithms Made Easy

Күн бұрын

Пікірлер: 36
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
We hope you all are enjoying our videos!!! Don't forget to leave a comment!!! Please like the video to support us!!! Questions you might like: ✅✅✅[ Tree Data Structure] : kzbin.info/aero/PLJtzaiEpVo2zx-rCqLMmcFEpZw1UpGWls ✅✅✅[ Graphs Data Structure] : kzbin.info/aero/PLJtzaiEpVo2xg89cZzZCHqX03a1Vb6w7C ✅✅✅[ January 2021 Leetcoding Challenge] : kzbin.info/aero/PLJtzaiEpVo2wCalBcRcNjXQ0C6ku3dRkn ✅✅✅[ February 2021 Leetcoding Challenge] : kzbin.info/aero/PLJtzaiEpVo2wrfvII0eZQsPm-MZCmHodm ✅✅✅[ March 2021 Leetcoding Challenge] : kzbin.info/aero/PLJtzaiEpVo2zH-YC5ZiptbAvw2QZkmyk9 ✅✅✅[ April 2021 Leetcoding Challenge] :kzbin.info/aero/PLJtzaiEpVo2z9PpcJcsl5j3RXutiTU-GB ✅✅✅[ December Leetcoding Challenge] : kzbin.info/aero/PLJtzaiEpVo2xo8OdPZxrpybGR8FmzZpCA ✅✅✅[ November Leetcoding Challenge] : kzbin.info/aero/PLJtzaiEpVo2yMYz5RPH6pfB0wNnwWsK7e ✅✅✅[ August Leetcoding Challenge] : kzbin.info/aero/PLJtzaiEpVo2xu4h0gYQzvOMboclK_pZMe ✅✅✅[ July Leetcoding challenges] : kzbin.info/aero/PLJtzaiEpVo2wrUwkvexbC-vbUqVIy7qC- ✅✅✅[ June Leetcoding challenges] : kzbin.info/aero/PLJtzaiEpVo2xIPptnCvUtKrUcod2zAKG ✅✅✅[ May Leetcoding challenges] : kzbin.info/aero/PLJtzaiEpVo2wRmUCq96zsUwOVD6p66K9e ✅✅✅Cracking the Coding Interview - Unique String: kzbin.info/aero/PLJtzaiEpVo2xXf4LZb3y_BopOnLC1L4mE Struggling in a question?? Leave in a comment and we will make a video!!!🙂🙂🙂
@aravindkumaresan2747
@aravindkumaresan2747 3 жыл бұрын
Hi if you get a TLE for this solution just add a Map before inserting to the tries So that the map gets only the last string if its duplicate with the largest index because of its unique keys nature and finally sort the Lists both prefix and suffix. This approach works great
@priyankabagal9269
@priyankabagal9269 2 жыл бұрын
Why to sort the lists?
@SR-we1vl
@SR-we1vl 2 жыл бұрын
Can you please show it implementation wise. Not able to get you!
@sdall2000
@sdall2000 2 жыл бұрын
Thanks! That solved the TLE for me. My Kotlin init code: init { // Handle duplicate words. Save off the highest index val wordMap = mutableMapOf() words.forEachIndexed { index, word -> wordMap[word] = index } // Now we only process unique words with their highest index value wordMap.forEach { word, index -> prefixTrie.insert(word, index) suffixTrie.insert(word.reversed(), index) } }
@rookiedrummer6838
@rookiedrummer6838 2 ай бұрын
best explanation crystal clear and to the point no non sense gyaan
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 2 ай бұрын
Thankyou !!
@hymnish_you
@hymnish_you 3 жыл бұрын
Perfect Solution and Wonderful Explanation 👌
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
Thanks
@srinaths284
@srinaths284 3 жыл бұрын
@@AlgorithmsMadeEasy TLE for this solution :( we need to optimize the complexity
@xueli5641
@xueli5641 3 жыл бұрын
Thanks for the clear and thorough explanation!
@milenitrivedi7561
@milenitrivedi7561 2 жыл бұрын
I tried writing cpp code for the same and its giving TLE.
@abhineshprajapati1989
@abhineshprajapati1989 2 жыл бұрын
// Just use hashmap, TLE will not occur. class Trie{ public : Trie *child[26]; vector index; Trie(){ for(int i=0;ichild[ch-'a']==NULL){ temp->child[ch-'a']=new Trie(); } temp = temp->child[ch-'a']; temp->index.push_back(i); } } vector find_string(string str,Trie *root){ Trie *temp = root; for(char ch:str){ if(temp->child[ch-'a']==NULL){ return {}; } temp = temp->child[ch-'a']; } return temp->index; } class WordFilter { public: Trie *prefix,*suffix; WordFilter(vector& words) { prefix = new Trie(); suffix = new Trie(); map dic; int len = words.size(); for(int i=0;i=0;i--){ if(st.find(pre[i])!=st.end()) return pre[i]; } return -1; } };
@suniljaiswal4415
@suniljaiswal4415 3 жыл бұрын
what if i would do like this root->index.push_back(i); root=root->child[ch]; see 11:50 in your video
@orangeshoes
@orangeshoes 3 жыл бұрын
Thanks, got it!
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
Thanks
@etarunsai5615
@etarunsai5615 2 жыл бұрын
could any one explain me what exactly Trie root = this , do
@aneeshkulkarni1739
@aneeshkulkarni1739 3 жыл бұрын
Why was Objects.equals() used instead of Integer.compareTo() method? IMO Integer.compareTo() is more readable. Also, intValue() could be called on the elements on the index list, and == can be used since it would trigger auto-unboxing. Otherwise a great solution
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
We can use both.
@praveenj3112
@praveenj3112 3 жыл бұрын
Thanks
@RupamSasmalYt
@RupamSasmalYt 2 жыл бұрын
now this approach is giving TLE
@kamaljosan4376
@kamaljosan4376 3 жыл бұрын
I am getting Time limit exceeded with the above solution, any idea what changed?
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
which test case?
@kamaljosan4376
@kamaljosan4376 3 жыл бұрын
@@AlgorithmsMadeEasy overall this solution gets TLE, does not show a specific test case.
@surikunal2362
@surikunal2362 3 жыл бұрын
Yes, I am getting TLE too. What to do.
@pgronop
@pgronop 3 жыл бұрын
@@surikunal2362 u should use the optimization on top of it like if the string "cat" comes three times, then store it one time only with the most latest index (or greatest index). This will make the TLE pass . The sample code looks like this Map w = new HashMap(); //Set visited = new HashSet(); for( int i=0;ia.getValue()-b.getValue()); for( int i=0;i
@priyankabagal9269
@priyankabagal9269 2 жыл бұрын
@@pgronop Why have you sorted l, I didnt get?
@cicciopasticcio8469
@cicciopasticcio8469 3 жыл бұрын
what about caching the previous results?
@TechOnScreen
@TechOnScreen 2 жыл бұрын
Time limit exceeded for the same solution ! pls suggest.
@TechOnScreen
@TechOnScreen 2 жыл бұрын
@@ashishbagul8733 yeah, m able to access. Thanks
@AnkitGupta-44
@AnkitGupta-44 2 жыл бұрын
It gives memory limit exceed 🥺
@srinaths284
@srinaths284 3 жыл бұрын
Yes it is TLE :(
@muthuvalli333
@muthuvalli333 3 жыл бұрын
👌🏻👌🏻👌🏻
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 жыл бұрын
Thanks
@souravchakraborty9777
@souravchakraborty9777 2 жыл бұрын
TLE Solution
@NihalSingh-ld2en
@NihalSingh-ld2en 2 жыл бұрын
Now, this code gives TLE...
Longest String Chain | Live Coding with Explanation | Leetcode - 1048
13:43
Algorithms Made Easy
Рет қаралды 10 М.
The Lost World: Living Room Edition
0:46
Daniel LaBelle
Рет қаралды 27 МЛН
LeetCode 745. Prefix and Suffix Search
19:55
Happy Coding
Рет қаралды 2,7 М.
Binary Tree Cameras | Live Coding with Explanation | Leetcode - 968
13:15
Algorithms Made Easy
Рет қаралды 11 М.
Design HashMap | Live Coding with Explanation | Leetcode - 706
12:17
Algorithms Made Easy
Рет қаралды 24 М.
N-Queens | Live Coding with Explanation | Leetcode - 51
11:45
Algorithms Made Easy
Рет қаралды 10 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 846 М.
Leetcode - Prefix and Suffix Search (Python)
20:23
Timothy H Chang
Рет қаралды 3,2 М.
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 190 М.
Implement Trie (Prefix Tree) - Leetcode 208
18:56
NeetCode
Рет қаралды 220 М.
The Lost World: Living Room Edition
0:46
Daniel LaBelle
Рет қаралды 27 МЛН