Concept Chamka ki nahi? Before Jumping to the solution, ek baar 15-20 minute baith ke, khud solve karne ki koshish karna, it will become easy for you. at 1:00:53 pre =2, so it must be at index 2 not at 4, just small correction at last
4:45 Brute Force Approach :- int n = s.length(); int maxLen = 0; // Iterate over the length of the prefix and suffix for (int len = 1; len < n; ++len) { string prefix; for(int i = 0; i< len; i++){ prefix.push_back(s[i]); }
string suffix; for(int i = n-len; i < n; i++){ suffix.push_back(s[i]); }
After seeing a lot video of KMT , This video gives crystal clear concept how and why we are able to reduce the Time complexity of finding prefix=suffix
0:05 introduction of KMP algorithm 1:04 Longest prefix suffix explaining 4:57 brute force approach 12:28 more optimised approach 22:56 Longest prefix and suffix method 23:35 examples with explanation of LPS 55:05 Code part 1:02:34 implementation part 1:05:36 Hw
Brute force in python: word = "ABGHCABGH" prefix = [] ans = "" for i in range(8): ans += word[i] prefix.append(ans) suffix = [] anss = "" for i in range(1, 9): anss = word[-i]+anss suffix.append(anss)
for index in range(len(prefix)): if(prefix[index] == suffix[index]): print (prefix[index])
My thought process behind O(n²) is that, for suffix, the string length will be like 1,2,3,4...n-1 and for prefix also it will be array of strings of length 1,2,3,4..n-1 So basically if we join two arrays string as compliment like from array1 we take string of length 1, and from array2 we take string n-1. Then from array1 we take 2, and from array2 n-2 and like so. Thus both array will compliment each other and will create an array of n strings and each string will have n length. So it will become basically O(n²)
Hello bhaiya, brute force approach to check for longest prefix and suffix int maxi = 0; int first = 0, last = s.size()-1; string one=""; string two=""; while(first0){ one+=s[first]; two=s[last]+two; if(one == two){ maxi = one.size(); } first++; last--; }
Rohit bhai median of two sorted array (Binary Search) wala question pe video bana do . Avi tak 10 video dekh chuka hu youtube par but samjh nhi aa rha hai pls expain🙏
sir your teaching style is really Baap Level.... i could able to solve this problem by own 5:00 class Solution{ public: int lps(string s) { // Your code goes here int n=s.length(); int i=0,j=1,maxlen=0,suff; //find first same character of prefix ans suffix if(n==1) return 0; while(j
Bhaiya mai exact algorithm nhi bana paya, lekin mai soch rha tha ki humlog is fact ko use ker sakte hai kya ki mid se start kare dhundna. then vo initial search space thora kam ho jayega. 🤔🤔
Concept Chamka ki nahi?
Before Jumping to the solution, ek baar 15-20 minute baith ke, khud solve karne ki koshish karna, it will become easy for you.
at 1:00:53 pre =2, so it must be at index 2 not at 4, just small correction at last
Yes bhaiya , concepts shined like a diamond💎
chamak gaya bhaiya
you are the one bro
Chamka 🤩
Yess 🎉
Bhaiya mza hi aa gaya... I've seen 4-5 videos for this topic, but unable to understand. Lekin jab aapka video dekha to sab chamak gaya...🤩🙏
4:45 Brute Force Approach :-
int n = s.length();
int maxLen = 0;
// Iterate over the length of the prefix and suffix
for (int len = 1; len < n; ++len) {
string prefix;
for(int i = 0; i< len; i++){
prefix.push_back(s[i]);
}
string suffix;
for(int i = n-len; i < n; i++){
suffix.push_back(s[i]);
}
if (prefix == suffix) {
maxLen = len;
}
}
return maxLen;
❤
you are very hardworking bhaiya. can be seen clearly from your intial submissions.Thank you for teaching us.grateful to u
The way you picked up the right examples to explain the tricky part is commendable. Great going brother👏👏
I couldn't understand this algorithm at first when I watched, but after some time, when I'm back again... its fixed in my head. Thank you sir !
After seeing a lot video of KMT , This video gives crystal clear concept how and why we are able to reduce the Time complexity of finding prefix=suffix
lecture is 1 hour, but I spent 4 hours. Then I cleared the concept of LPS. Thank you, sir.
but i spent 7hrs with notes
Your understanding is crystal clear thats why you are able to explain this flawlessly..hats off to your dedication!!!
very good explanation of such a complex logic. Nowhere find this kind of explanation. Thanks for making this video. 🙏
Finally understand LPS after wasting so many times in other garbage videos. Thank you bro...
24:39 to 27:05
49:22 to 54:30 conclusion of whole LPS concept
bhai bahut baar dekha loop mein samjh aaa gya explanation god level bhai really god level
no one beat rohit sir 🔥
Awesome explanation sir! So much better than any paid course. Thank you thank you thank you!!!
0:05 introduction of KMP algorithm
1:04 Longest prefix suffix explaining
4:57 brute force approach
12:28 more optimised approach
22:56 Longest prefix and suffix method
23:35 examples with explanation of LPS
55:05 Code part
1:02:34 implementation part
1:05:36 Hw
Bhai tum ne ye kyo kiya ?
chamka diya bhaiya best dsa course in history ever for logic building
9:10 space complexity is O(2N) same as O(N)
But bro string ka array so o N2 na??
Literally one of the best lecture bhaiya...aLWAYS get motivated by seeing u
really a great teacher ,means leagend god level bhai
Best explanation ❤ after watching whole video, i assure you (viewers) that you're at right place ✅️
Understood all. For the viewers you have to give it a brief thought and dry run it in mid so that it becomes intuitive
Bro you just nailed it!🔥
Pahadi always rocks ❤
thank you bhaiya, after struggling too much for kmp, today I got the clarity
Best explanation ❤ KMP done ✅
Easy to understand than other tutorials and blogs also.
I don't know why college teachers don't teach these questions in this way.
You are great, Bhaiya. Love from Uttarakhand ❤️
Hats off to you sir your content is best.
sir nice explanation
aikdum aaram se samajh aaya
Thank you Rohit sir/bhaiyya.....❤
Maja aa gya bhai ... Seriously enjoyed the way you revealed the suspense of LPS wala technique
Imagine If One Can Discover KMP in the interview itself to solve, Just GOD LEVEL🥶🥶🥶
Not possible
Too hard to figure it out....
you made this topic easy thanks
Too good bhaiya.
Brute force in python:
word = "ABGHCABGH"
prefix = []
ans = ""
for i in range(8):
ans += word[i]
prefix.append(ans)
suffix = []
anss = ""
for i in range(1, 9):
anss = word[-i]+anss
suffix.append(anss)
for index in range(len(prefix)):
if(prefix[index] == suffix[index]):
print (prefix[index])
Space Complexity of brute force is O(2N) ~ O(N)
9:05 Space complexity will be O(n^2) because every element of prefix or suffix array will have kind of n length.
I think the space complexity will be O(n)
i am also think its o(n), because in space n+n = n.
My thought process behind O(n²) is that, for suffix, the string length will be like 1,2,3,4...n-1 and for prefix also it will be array of strings of length 1,2,3,4..n-1
So basically if we join two arrays string as compliment like from array1 we take string of length 1, and from array2 we take string n-1. Then from array1 we take 2, and from array2 n-2 and like so.
Thus both array will compliment each other and will create an array of n strings and each string will have n length. So it will become basically O(n²)
u r gae@@joydeep-halder
2n?
hoga kya
best explanation 🤩
GREAT EXPLANATION🤩
Great Lecture.
hardest hardest kh kr asani se samjha dia wah
Tq bhaiya, aaj kuch naya seekha😄😄
Love u bhiya ❤️
Thank you sur for this amazing explanation
Sach me bhaiya tussi great ho 🎉🎉❤❤❤ kal ke DAA ke exam me fod ke aunga🎉❤
bhot ache se samjh aagya bhaiya
Hello bhaiya, brute force approach to check for longest prefix and suffix
int maxi = 0;
int first = 0, last = s.size()-1;
string one="";
string two="";
while(first0){
one+=s[first];
two=s[last]+two;
if(one == two){
maxi = one.size();
}
first++;
last--;
}
Aapki jitni tarif kare utni kam hai ❤
Done todays lecture thank Bhaiya😊
chamak gya bhaiya ek dam
bhaiya concept bhi chamka aur code bhi
#180dayscodingchallenege
#coderArmy
Thanks Bhaiya...❤🎉
Done Bhaiya... Day 58/180 ✅
best explaination..
Rohit bhai median of two sorted array (Binary Search) wala question pe video bana do . Avi tak 10 video dekh chuka hu youtube par but samjh nhi aa rha hai pls expain🙏
bhot badhiya samjhaya
Chamka bhaiya chamka 👍🏻
Thanks bhaiya. chamak gya
Best❤️💚
Great explanation
Bhaiya Radhe Radhe 🙏
bhaiya chamak gya
Ram Ram Coders 😊❤🙏
Day 58/180 done 👍 #180Daysofcode
Good morning Bhaiya ❤
poora kiliear ho gaya sir
Amazing explanation
thanks sir
sir your teaching style is really Baap Level....
i could able to solve this problem by own
5:00
class Solution{
public:
int lps(string s) {
// Your code goes here
int n=s.length();
int i=0,j=1,maxlen=0,suff;
//find first same character of prefix ans suffix
if(n==1) return 0;
while(j
best KMP algorithm video ❤
Day 58 👍✅ Chamak Gaya
bhaiya at 30:42 why 3 aise toh piche jo hmne 5 th index pe 0 likha vahan toh 2 likh skte the
\
Day 58/180 done 👍
Thank u😊
Day 58 ✅🔥
Good morning boss ❤
Thanks Bhai ❤
Day 58/180 done ✅✅✅
Good morning bhaiya #day58
9:11 On2 hogi kyunki ham string ka array banayege jo string is a type of array , so 2d array jesa kaam hoga
If you teach in english non hindi audience will also watch your videos bro
while(my_life)
{
Rohit _bhaiya= aura++;
}
at 1:00:53 pre ==2, so it must be at index 2 not at 4
right, thanks
besttttt
Bhaiya mai exact algorithm nhi bana paya, lekin mai soch rha tha ki humlog is fact ko use ker sakte hai kya ki mid se start kare dhundna. then vo initial search space thora kam ho jayega. 🤔🤔
bhaiy aapne to garda kar diya chutki bajake KMP ho yakuch bhi ho rohit bhaiya ke aage koi bhi algoritham kuch bol sakta hai kya
Muje pta hi nh chla aap kb aa ye 6 bje
best
🎉
Day 58/180 Done✅✅ #CoderArmy #180DaysofCode 🎉🎉
31:50 Bhaeya chamak gya haain
Now I can even explain better than my professor 😂😂💀💀
bhaiya i think , 52:00 me D me LPS ki value 2 hogi . ky mai galat hu?
Thankyou amazing explanation
Good morning 🌞
#lecture completed after 4 days
Space complexity:O(n)
27:38 mujhe laga hum do hamare do 🤣
❤
Day 58 👍👍
Is this last video on strings?
no probably 1 or 2 lecture aur honge