Leetcode 32 Longest Valid Parentheses
Vložit
- čas přidán 8. 06. 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
One of the best Solution , Mam do the leetcode problems like this way its very help to us
ok sir
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
wasn't able to understand why two traversals : start to end and end to start, just understood, thanks bakrola mam
Glad it helped!
nice solution, great logic
mast explain kiya hain :)
Good
My approach was same but I was not doing checking in reverse direction, thanks
Great 👍
nice one
Thanks
very informative vedio
🎉💥👑
great maja aagaya
what if that would be a stack and they ask for thw range between indexes at longest parantheses
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;
}
}
never found such clear explanation
Thanks for sharing! I am glad you found it helpful!
well explained great 👍
Thank you Saroj Ji 🙏 Make sure you share it with others who may find it helpful 😊
Pratiksha explanation is too good also u are too cute 🥰
Thank you!
I came here just to see her beauty ❤
Great explanation
Glad it was helpful!
Very Clear
Glad to hear that
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 😊
nice🎉
Glad you liked it ! Make sure to share it with your friends 🙏
@@pratikshabakrola I did ;)
turunin
s =
")(", wrong for this input
Not working for some test cases
Beauty with Talent
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
aapke aashirwaad se mera package 15 crore ka lag jaayega
😌
My well wishes to you!
name se laga Indian hai but awaj se angrez , Kya bawasir hai 🤣, BTW nice explaination
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!
Glt solution hai bhai 🫠
wannabees be faking day and night
Kind of feels like this solution is wrong
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