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])
4:53 //Brute force approach //pass all the test cases but time complexity is O(n²) class Solution { public: int lps(string str) { if(str.size()==1) return 0; int start=0,end=1; while(end
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²)
My code for brute force approach at 4:40 text = "ABCDEABCD" #prefix array list1=[] for i in range(len(text)-1): if len(list1)==0: list1.append(text[i]) else: res=list1[i-1]+text[i] list1.append(res) for i in list1: print(i) #suffix array list2=[] j=len(text)-1 while j>0: if len(list2)==0: list2.append(text[j]) else: res=text[j]+list2[-1] list2.append(res) j-=1 for i in list2: print(i) # calculating longest prefix suffix max_length=0 for prefix in list1: if prefix in list2: length=len(prefix) max_length=max(max_length,length) print(max_length)
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--; }
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
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🙏
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 🎉
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;
❤
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...🤩🙏
one and only the best Explanation on youtube...
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 !
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
Finally understand LPS after wasting so many times in other garbage videos. Thank you bro...
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
Your understanding is crystal clear thats why you are able to explain this flawlessly..hats off to your dedication!!!
24:39 to 27:05
49:22 to 54:30 conclusion of whole LPS concept
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 ?
no one beat rohit sir 🔥
very good explanation of such a complex logic. Nowhere find this kind of explanation. Thanks for making this video. 🙏
I don't know why college teachers don't teach these questions in this way.
You are great, Bhaiya. Love from Uttarakhand ❤️
bhai bahut baar dekha loop mein samjh aaa gya explanation god level bhai really god level
Awesome explanation sir! So much better than any paid course. Thank you thank you thank you!!!
9:10 space complexity is O(2N) same as O(N)
But bro string ka array so o N2 na??
Imagine If One Can Discover KMP in the interview itself to solve, Just GOD LEVEL🥶🥶🥶
Not possible
Too hard to figure it out....
Literally one of the best lecture bhaiya...aLWAYS get motivated by seeing u
Understood all. For the viewers you have to give it a brief thought and dry run it in mid so that it becomes intuitive
chamka diya bhaiya best dsa course in history ever for logic building
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 ✅️
thank you bhaiya, after struggling too much for kmp, today I got the clarity
Bro you just nailed it!🔥
Pahadi always rocks ❤
Best explanation ❤ KMP done ✅
Easy to understand than other tutorials and blogs also.
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])
sir nice explanation
aikdum aaram se samajh aaya
Hats off to you sir your content is best.
Too good bhaiya.
4:53
//Brute force approach
//pass all the test cases but time complexity is O(n²)
class Solution {
public:
int lps(string str) {
if(str.size()==1)
return 0;
int start=0,end=1;
while(end
Maja aa gya bhai ... Seriously enjoyed the way you revealed the suspense of LPS wala technique
Space Complexity of brute force is O(2N) ~ O(N)
Thank you Rohit sir/bhaiyya.....❤
you made this topic easy thanks
Great Lecture.
GREAT EXPLANATION🤩
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 🤩
Thank you sur for this amazing explanation
Tq bhaiya, aaj kuch naya seekha😄😄
thanks sir
hardest hardest kh kr asani se samjha dia wah
bhot badhiya samjhaya
bhot ache se samjh aagya bhaiya
Aapki jitni tarif kare utni kam hai ❤
Sach me bhaiya tussi great ho 🎉🎉❤❤❤ kal ke DAA ke exam me fod ke aunga🎉❤
Thanks bhaiya. chamak gya
chamak gya bhaiya ek dam
best explaination..
My code for brute force approach at 4:40
text = "ABCDEABCD"
#prefix array
list1=[]
for i in range(len(text)-1):
if len(list1)==0:
list1.append(text[i])
else:
res=list1[i-1]+text[i]
list1.append(res)
for i in list1:
print(i)
#suffix array
list2=[]
j=len(text)-1
while j>0:
if len(list2)==0:
list2.append(text[j])
else:
res=text[j]+list2[-1]
list2.append(res)
j-=1
for i in list2:
print(i)
# calculating longest prefix suffix
max_length=0
for prefix in list1:
if prefix in list2:
length=len(prefix)
max_length=max(max_length,length)
print(max_length)
Love u bhiya ❤️
Great explanation
Thanks Bhaiya...❤🎉
Bhaiya Radhe Radhe 🙏
Chamka bhaiya chamka 👍🏻
poora kiliear ho gaya sir
bhaiya chamak gya
Done todays lecture thank 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--;
}
Done Bhaiya... Day 58/180 ✅
Ram Ram Coders 😊❤🙏
Day 58/180 done 👍 #180Daysofcode
Best❤️💚
If you teach in english non hindi audience will also watch your videos bro
nice
Good morning bhaiya ❤❤
Amazing explanation
9:11 On2 hogi kyunki ham string ka array banayege jo string is a type of array , so 2d array jesa kaam hoga
bhaiya concept bhi chamka aur code bhi
#180dayscodingchallenege
#coderArmy
Time complexity O(2n-2) for brute force ?
Now I can even explain better than my professor 😂😂💀💀
Thank u😊
longest COMMON prefix and sufix wuld be more appropriate usage of words I guess
Good morning boss ❤
Day 58/180 done 👍
Day 58 👍✅ Chamak Gaya
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
Thanks Bhai ❤
at 1:00:53 pre ==2, so it must be at index 2 not at 4
right, thanks
Day 58/180 done ✅✅✅
Good morning bhaiya #day58
Day 58 ✅🔥
Good morning 🌞
#lecture completed after 4 days
while(my_life)
{
Rohit _bhaiya= aura++;
}
🎉
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🙏
besttttt
Muje pta hi nh chla aap kb aa ye 6 bje
best
31:50 Bhaeya chamak gya haain
27:38 mujhe laga hum do hamare do 🤣
bhaiya at 30:42 why 3 aise toh piche jo hmne 5 th index pe 0 likha vahan toh 2 likh skte the
\
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
Clear hai ?? Haan ji bhaiya clear hai 😂😂wahh😂😂
27:42 hum do humare do 😂
Space complexity:O(n)