Find the longest Palindrome in a string | Love Babbar DSA Sheet | Amazon🔥
Вставка
- Опубліковано 5 лют 2025
- #competitiveprogramming #dsasheet #interviewpreparation
In this video I have solved the problem of the sheet i.e. Write a program to find the longest Palindrome in a string.[ Longest palindromic Substring]
Complete Explaination with code.
String question Playlist = • Love Babbar DSA 450 Qu...
Array question Playlist = • Love Babbar DSA 450 Qu...
Love Babbar DSA Sheet : drive.google.c...
Hope you like it. Comment if you have any doubt
LIKE | SHARE | SUBSCRIBE
If u guys complete these 450 questions definitely your channel will become very famous 🔥
bhai starting me btaya h asi jgh jha bb equal mlte h but usse phle to aa equal milege uska kya (1:16-1:20) you directly jumped it bb without saying aa. Your logic is good but explain properly
At 1:24 min, "aa" is also equal at first so then why does the pointer stop only "bb". Explain Please.
Thank You Bhaiya, Abse yahi channel follow hoga till the placement.
for those who want to do this question in O(N) complexity can learn about Manacher’s Algorithm
pls explain the intuition behind the algorithm.
Bro Dry Run The Case Explain Code With Taking Example.
wow outstanding approach
great explaination !!
thanks bhai for this solution , i saw other youtube chnanels and they are directly starting from dp tabulation , your solution was easiest to understand
Awesome!
very nice explanation bro....thanks
Bro please clear my doubt do we need to write code only to satisfy the given inputs below problem or else for any input
Please reply
💢💢💢Excellent work💢💢💢
Keep it up brother 👍👍
Keep it up 👍👍👍very nice explanation
nice explaination
Thanks 😀
hey , how do we check if the current substring length is greater than the previous one ??
PS:- what is the use of end=1 and then comparing h-l+1>end??
To update the starting index and length of palindromic substring if its length is greater than previous one(stored in end variable)
chutiye dry run kr mc
Thank you Bhai ! for simplest solution in of this problem on youtube !
If we are giving input as "aba " Then output is coming out to be an "a"..... But it should comeout aba as it is longest substring?????.... Plzz clear my doubt
Keep going brother😊
Crystal clear explanation,🙇🙇🙇
bhai isme hamne to comments likh die odd and even string , but code mein check ni lagana chahiye ki agar length odd hui to alg while loop and even hui to alag while loop
bhai tum galat samjh rhe . agar samjhna hai tho reply kro samjhata hu
Dhnyawaad
Thanks bro
We here to check if length of string is even or odd?
string longestPalin (string S) {
// code here
int start=0;
int end=0;
int low,high;
int n=S.length();
for(int i=0;i=0 and high
thank you bro this is helpful
//java code
class Solution{
static String longestPalin(String S){
// code here
int start=0;
int end=0;
int low,high;
int n=S.length();
for(int i=0;i=0 && high
Bro please clear my doubt do we need to write code which satisfies only the given input below problem or for any input please reply
obviously any input given bro, condition is the input type must be same @@intrestingscienceworld5848
intuition kaise aai iss approach ki>
How the compiler knowing which while loop to use, you didn't check if length of the string is even use this or else
Please help me ? Where I'm wrong ?
I got it where you are going wrong... Basically for each i we are checking a even as well as odd substrings and which ever will give the better result we will print that...see their in odd substrings section we are updating l and h
@@CodeLibrary thank you so much my clearing my doubt I've been scratching my head since yesterday
You are the best 🔥
the other guy on this channel explain well, nd you need to improve bro in explaination.
at 5:37 , you didnt initialize the end, why did you miss it?
how can you write your own main method in GFG i dont think it is possible
possible bro
So for each character in the given string we have to check both the conditions ?? .If so can you explain why we have to check both the conditions ?
because we don't whether our substring will be odd or even
How did you remove the default code in gfg practice ?
he is having premium subscription of GFG , so he can change his IDE according to him :)
I am facing problem,I used your approach to solve the problem, I tried to compile and run it on GFG ,it showed the correct output but when I submitted it,it shows that you got wrong answer,even I tried this on different IDE and all of them showed correct answers,plz reply
Put endl after calling palindrome(string s) in the main function.
@anyone, why we are sending start+end-1 instead of end. Please explain?
We might be getting the value of end smaller than start....that's why he has considered start+end-1
can someone please explain me, why we passed (start+end-1), as end parameter in printString function and not (end-start+1)?
Lets take ex of caabbabd here the start is 2 so they passed it so that the printing starts from here and till start+end-1 which would be 2+5-1=6(in S, 6th is the index which contains the char just after the end char of the palindrome string) so if it prints till < 6 it will be basically the palindrome string. Also I think they should have just written
"wtwkee" this code will produce "ee" but the answer is "wtw" your logic failed brother anyway it added a new thinking approach to us.
code not working now
Amazing explanation 😍♥️
"wtwosileez" wrong for this test case...ur code will return "ee"..but actual output is "wtw" .
Not working on leetcode.
if string will be "rajjjkmnmkj" then its output should be "jkmnmkj" but this code will return jj
hey can u explain me if my element at 0th and 1th position are same and if we do low__then that low which is allready points to 0 decreases to -1then how this soln is correct?
Exactly, I have also the same question
bhai ye batao tumse saare ques kese ho jaa rahe hai ? kahi atakte nhi ho kya aur kitna tym dete ho pr ques ke optimal soln tk aane mein?
bhai ye sre ans gfg pe mil jate he brute optimal or best,ye bs explain kr rhe he.
sir can u explain how this is 0(n^2) complexity
Because
For first loop it's O(n) and two loops are inside it.
So, O(n*(N+N)) = O(n*n)
Also explain java solution code
What I am doing wrong, anybody can help
string longestPalin (string S) {
// code here
string z="";
int n=S.length();
int l=0,L=0;
int r=0,R=0;
for(int i=1;i=0&&rR){
L=l;
R=r-l+1;
}
l--;
r++;
}
l=i-1;
r=i+1;
while(S[l]==S[r]&&l>=0&&rR){
L=l;
R=r-l+1;
}
l--;
r++;
}
}
for(int i=L;i
If I am giving abaa it is giving aa as an output..... Why is it so???.... It should give aba
what about "abcd" it will not print "a" in this case
no it will print 'a' bro as start is not changed so far
try for this string "eeef" it may fail
It'll fail for string "abb"
Bhai tum chhor do yaar padhana, aadhi chize to tum explain bhi nahi krte ho ki konsa variable kahan se initialize ho raha or kya initial value hai...
someone please explain me what is h-l+1>end clearly .....?
we are just checking if the current length of palindrome is greater than the previous length if so we will update...Here "h" and "l" are respectively pointing to the start and end of the current palindrome substring and "end" contains the length of the previously found out palindrome substring.
@@siri3359 why will the length of previously found out palindrome substring be equal to "end" and not "end-start"?
@@niharsrivastava end variable means length of max string. start variable means starting position of max string. h-l+1 is length of the current string. In the end, he is passing starting position and ending position to print the string using his created function
Why Lcs is not useful here ??
coz lcs works for subsequence and it may be palindrome or may be not
could have been a better explanation
Sir
Kindly explain in English
Many users may not understand Hindi
i didnt understand the line number 29 and 30, very bad explaination, just writing the code
dont worry, will update the older videos
Not so hard
L explanation
Ghatiya explanation
true
WRONG!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
true