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

ความคิดเห็น • 53

  • @sivan2878
    @sivan2878 4 หลายเดือนก่อน +1

    Great video, thanks a lot Pratiksha

  • @nguyenbach4710
    @nguyenbach4710 11 หลายเดือนก่อน +1

    plz don't stop the way u explained so clearly and specify thankyou very much

    • @pratikshabakrola
      @pratikshabakrola  11 หลายเดือนก่อน +1

      Hello Nguyen,
      Thank you for your feedback! Appreciate it! Will upload more videos soon!

  • @holly_singh
    @holly_singh 10 หลายเดือนก่อน +2

    great video, can you please make videos of graph questions ? Esp the ones that are not solved on other channels

  • @priyanshu5407
    @priyanshu5407 2 หลายเดือนก่อน +2

    nice one

  • @prashantbhati8705
    @prashantbhati8705 หลายเดือนก่อน

    mast explain kiya hain :)

  • @neetankumar4449
    @neetankumar4449 10 หลายเดือนก่อน +1

    wasn't able to understand why two traversals : start to end and end to start, just understood, thanks bakrola mam

  • @user-gq3xu4vj8d
    @user-gq3xu4vj8d 5 หลายเดือนก่อน

    very informative vedio

  • @abhaychaurasiya5548
    @abhaychaurasiya5548 10 หลายเดือนก่อน +1

    never found such clear explanation

    • @pratikshabakrola
      @pratikshabakrola  10 หลายเดือนก่อน

      Thanks for sharing! I am glad you found it helpful!

  • @zeynepergul4768
    @zeynepergul4768 7 หลายเดือนก่อน

    what if that would be a stack and they ask for thw range between indexes at longest parantheses

  • @sarojkumar-nu8vo
    @sarojkumar-nu8vo 2 ปีที่แล้ว

    well explained great 👍

    • @pratikshabakrola
      @pratikshabakrola  2 ปีที่แล้ว

      Thank you Saroj Ji 🙏 Make sure you share it with others who may find it helpful 😊

  • @snehalmishra5429
    @snehalmishra5429 2 หลายเดือนก่อน +1

    My approach was same but I was not doing checking in reverse direction, thanks

  • @JayPrajapati-lj8pw
    @JayPrajapati-lj8pw ปีที่แล้ว +1

    great maja aagaya

  • @vineeshashwin2697
    @vineeshashwin2697 8 หลายเดือนก่อน

    🎉💥👑

  • @singhji4149
    @singhji4149 11 หลายเดือนก่อน

    Great explanation

  • @pratikshabakrola
    @pratikshabakrola  2 ปีที่แล้ว +1

    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;

    }
    }

  • @Area-fd8ht
    @Area-fd8ht 3 หลายเดือนก่อน +1

    Pratiksha explanation is too good also u are too cute 🥰

  • @mohammedilyas8824
    @mohammedilyas8824 2 ปีที่แล้ว +1

    Ma'am pls make videos on most important questions for sde role fresher

    • @pratikshabakrola
      @pratikshabakrola  2 ปีที่แล้ว +1

      Hello Mohammed,
      I will try to put something together on that topic. Thank you for suggesting that.

  • @deepakkumar13204
    @deepakkumar13204 10 หลายเดือนก่อน

    Well explained mam ❤

  • @vvek_7
    @vvek_7 8 หลายเดือนก่อน

    Very Clear

  • @mayurs9319
    @mayurs9319 2 ปีที่แล้ว +1

    nice🎉

    • @pratikshabakrola
      @pratikshabakrola  2 ปีที่แล้ว +1

      Glad you liked it ! Make sure to share it with your friends 🙏

    • @mayurs9319
      @mayurs9319 2 ปีที่แล้ว +1

      @@pratikshabakrola I did ;)

  • @Karthik-ev7jy
    @Karthik-ev7jy 4 หลายเดือนก่อน

    Not working for some test cases

  • @24_Focus
    @24_Focus หลายเดือนก่อน

    turunin

  • @UnspokenTears
    @UnspokenTears 7 หลายเดือนก่อน

    class Solution {
    public int longestValidParentheses(String s) {
    int c=0;
    for(int i=0;i

    • @adi9003
      @adi9003 5 หลายเดือนก่อน +1

      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.

  • @gamerversez5372
    @gamerversez5372 9 หลายเดือนก่อน

    I think you should give proper explanation why another traversal is needed

  • @vinaysen6710
    @vinaysen6710 9 หลายเดือนก่อน

    Beauty with Talent

  • @AmitKumar-fk8mm
    @AmitKumar-fk8mm 7 หลายเดือนก่อน +1

    aapke aashirwaad se mera package 15 crore ka lag jaayega
    😌

  • @princebhati6376
    @princebhati6376 2 ปีที่แล้ว +1

    How do you get the job in usa, can u make a video about that.

    • @pratikshabakrola
      @pratikshabakrola  2 ปีที่แล้ว

      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!

    • @princebhati6376
      @princebhati6376 2 ปีที่แล้ว

      @@pratikshabakrola , i think linkedin would be better.

    • @pratikshabakrola
      @pratikshabakrola  2 ปีที่แล้ว

      +Prince bhati Yes, I agree. That’s a great idea!

  • @satyamchoudhary2573
    @satyamchoudhary2573 5 หลายเดือนก่อน

    name se laga Indian hai but awaj se angrez , Kya bawasir hai 🤣, BTW nice explaination

  • @satyamchoudhary2573
    @satyamchoudhary2573 5 หลายเดือนก่อน

    s =
    ")(", wrong for this input

  • @ManishRaj-zm5gs
    @ManishRaj-zm5gs 9 หลายเดือนก่อน +1

    galat hai

    • @pratikshabakrola
      @pratikshabakrola  7 หลายเดือนก่อน

      Feel free to share the code that you think is right for our viewers

    • @Karthik-ev7jy
      @Karthik-ev7jy 4 หลายเดือนก่อน

      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