Leetcode 32 Longest Valid Parentheses
ฝัง
- เผยแพร่เมื่อ 8 มิ.ย. 2022
- Leetcode 32, Longest Valid Parentheses, 32. Longest Valid Parentheses, Leetcode 32. Longest Valid Parentheses, Leetcode Java Solution, Leetcode Java Solutions, Google Interview Question, amazon interview Question, Leetcode Java,Java solutions #Leetcode , #LeetcodeSolutions, #LeetcodeSolution #LeetcodeJavaSolutions #LeetcodeJavaSolution
Connect with me on Facebook : / pratikshabakrola
Subscribe to my channel: / @pratikshabakrola
Great video, thanks a lot Pratiksha
plz don't stop the way u explained so clearly and specify thankyou very much
Hello Nguyen,
Thank you for your feedback! Appreciate it! Will upload more videos soon!
great video, can you please make videos of graph questions ? Esp the ones that are not solved on other channels
nice one
Thanks
mast explain kiya hain :)
wasn't able to understand why two traversals : start to end and end to start, just understood, thanks bakrola mam
Glad it helped!
very informative vedio
never found such clear explanation
Thanks for sharing! I am glad you found it helpful!
what if that would be a stack and they ask for thw range between indexes at longest parantheses
well explained great 👍
Thank you Saroj Ji 🙏 Make sure you share it with others who may find it helpful 😊
My approach was same but I was not doing checking in reverse direction, thanks
Great 👍
great maja aagaya
🎉💥👑
Great explanation
Glad it was helpful!
class Solution {
public int longestValidParentheses(String s) {
int left=0;
int right=0;
int max=0;
for(int i=0;ileft)
{
left=0;
right=0;
}
}
left=0;
right=0;
for(int i=s.length()-1;i>=0;i--)
{
if (s.charAt(i)=='(')
left++;
else
right++;
if(left==right)
{
max=Math.max(max,left*2);
}else if(left>right)
{
left=0;
right=0;
}
}
return max;
}
}
Pratiksha explanation is too good also u are too cute 🥰
Thank you!
Ma'am pls make videos on most important questions for sde role fresher
Hello Mohammed,
I will try to put something together on that topic. Thank you for suggesting that.
Well explained mam ❤
Thanks a lot 😊
Very Clear
Glad to hear that
nice🎉
Glad you liked it ! Make sure to share it with your friends 🙏
@@pratikshabakrola I did ;)
Not working for some test cases
turunin
class Solution {
public int longestValidParentheses(String s) {
int c=0;
for(int i=0;i
you are only considering strings which which have ')' just after '(' -> for example, ()()()
but this code will fail to answer correctly when I give ((((())))), it is correct string but according to your logic it is not correct.
I think you should give proper explanation why another traversal is needed
Good feedback! Thanks
Beauty with Talent
aapke aashirwaad se mera package 15 crore ka lag jaayega
😌
My well wishes to you!
How do you get the job in usa, can u make a video about that.
Thank you for the suggestion. I will see if I can put something together on that subject, if I am not able to make a video, I will share some tips via email/call. You can follow my Facebook page and stay connected!
@@pratikshabakrola , i think linkedin would be better.
+Prince bhati Yes, I agree. That’s a great idea!
name se laga Indian hai but awaj se angrez , Kya bawasir hai 🤣, BTW nice explaination
s =
")(", wrong for this input
galat hai
Feel free to share the code that you think is right for our viewers
public class Solution {
// DO NOT MODIFY THE ARGUMENTS WITH "final" PREFIX. IT IS READ ONLY
public int solve(final String A) {
Stack stack = new Stack();
int maxLen = 0;
stack.push(-1); // Push -1 to represent the starting index
for (int i = 0; i < A.length(); i++) {
if (A.charAt(i) == '(') {
stack.push(i); // Push the index of opening parenthesis
} else {
stack.pop(); // Pop the matching opening parenthesis index
if (!stack.isEmpty()) {
maxLen = Math.max(maxLen, i - stack.peek()); // Calculate length of valid substring
} else {
stack.push(i); // If no matching opening parenthesis found, push current index
}
}
}
return maxLen;
}
}
@@pratikshabakrola