Parenthesis Checker | Valid Parentheses Leetcode | Balanced Parentheses Hackerrank | DSAOne #43

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ส.ค. 2024
  • Hey guys, In this video, We're going to solve another very famous Interview Problem called - Parentheses Matching Problem.
    code: www.geeksforge...
    Practice questions: www.interviewb...
    🥳 Join our Telegram Community:
    Telegram channel: telegram.me/re...
    Telegram group: telegram.me/ds...
    🚀 Follow me on:
    Instagram: / anuj.kumar.sharma
    Linkedin: / sharma-kumar-anuj
    Twitter: / realanujbhaiya
    💸 Use coupon code ANUJBHAIYA on GeeksforGeeks to avail discounts on courses!
    📚 Complete DSA Playlist: • DSA-One Course - The C...
    Complete Android Development Playlist: • Android Development Tu...
    Hashtags:
    #anujbhaiya #dsaone
    Ignore these tags:
    parenthesis checker
    valid parentheses
    anuj bhaiya
    valid parentheses leetcode
    valid parentheses leetcode java
    balanced parentheses hackerrank solution
    balanced parenthesis
    balanced paranthesis
    balanced parentheses
    longest valid parentheses
    parentheses
    valid parenthesis
    valid paranthesis
    balanced brackets
    generate parentheses leetcode
    minimum swaps for bracket balancing
    sherlock and parentheses solution
    stack in java
    valid substring
    20. valid parentheses
    stack dsa
    balanced parentheses problem
    dsa in java
    generate parentheses
    minimum remove to make valid parentheses
    remove invalid parentheses
    parentheses and brackets
    stack
    stack in dsa
    stack questions
    stacks in java
    valid parentheses leetcode c++
    balanced brackets hackerrank solution
    create a program to return array of all balanced parenthesis.
    dense bracket sequence solution
    leetcode valid parentheses
    stack data structure
    stack in data structure
    )
    anuj bhaiya dsa
    anuj bhaiya java
    apna college
    boolean parenthesization
    check for a matching contact in your org
    create a program to return array of all balanced parenthesis
    expression contains redundant bracket or not
    generate parenthesis
    leetcode 20
    parenthesis
    stack java
    stack problems
    time complexity analysis
    valid parentheses java
    valid parentheses leetcode python
    2116. check if a parentheses string can be valid

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

  • @dheerajkhushalani2619
    @dheerajkhushalani2619 2 ปีที่แล้ว +17

    In opening(char c) method it must be checked by double equals to ==, not by single assignment operator.

  • @HEMANTKUMAR-vb5bc
    @HEMANTKUMAR-vb5bc 2 ปีที่แล้ว +12

    you are amazing ....! and few days before i saw your teaching technique its amazing after watching your video i feel very much confident and concentrate more to study. Thank you a lot for making this kind of videos.

  • @sandeepmalviya3166
    @sandeepmalviya3166 2 ปีที่แล้ว +8

    Your coding logic is very strong 💪.

  • @krishnarajput5008
    @krishnarajput5008 2 ปีที่แล้ว +3

    Literally i am searching for this problem now and I got suggestion of these vodio

  • @stupidatmaa2813
    @stupidatmaa2813 2 ปีที่แล้ว +16

    Amazon mai job karne ke liye bohot papad bel naa padta hai...lekin aap chor diya isiliye ki aap apna Commitment pura kar sako .....bohot bura laga 😒you are great Anuj bhayia ❤️🙏

  • @tejasukalkar2199
    @tejasukalkar2199 2 ปีที่แล้ว +5

    Sir I'm getting error as bad operand types for binary operator '||' & bad operand types for binary operator '&&' for this code

  • @techbhupi9398
    @techbhupi9398 2 ปีที่แล้ว +11

    From now on I will definitely like your every video to support you as you have done same for all of us 🔥❤️

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

    BHIYA......YOU ARE THE BEST TEACHER EVER ...WE WILL ALWAYS TRUST YOU AND ALWAYS BE SUPPORTIVE OF YOUR BEAUTIFUL JOURNEY ......WE LOVE YOU ANUJ BHIYA...AB THO AAPKE UPPER RESPECT AUR BHED GAYA HAIN MERA.....YOU ARE JUST AMAZING ...YOU NOT ONLY GUIDE ME..BUT INSPIRE ME A LOT BHIYA. I WANT TO BECOME LIKE YOU BHIYAA...😍❤🧡 YOUR JOURNEY IS VERY MUCH INSPIRATIONAL TO US ...FROM SUPER 30 TO AMAZON ..AND A PRO-TH-camR..AND WHAT NOT.....MORE OVER YOU ARE THE BEST CREATION...THANK YOU SO MUCH FOR YOUR EFFORTS TOWARDS US....AND MAKING OUR LIVES EASY AND NOT LETTING US FACE THE SAME STRUGGLE WHICH YOU FACED ...THERE'S NO ONE LIKE YOU!!!!... I AM 2 nd YEAR STUDENT AND I AM SO HAPPY THAT I CAUGHT YOU AT RIGHT TIME. THE WAY YOU EXPLAIN EACH AND EVERYTHING IN DETAIL ...WITH YOUR BEAUTIFUL SMILE ON YOUR FACE ...KEEPS PUSHING ME AHEAD ...TO WORK MORE AND HARDER ON IT......!! I KNOW I CAN DO IT ....ALL BECAUSE OF YOU...🧡🙏🙏🙏🙏 YOU ARE MAKING THIS TH-cam PLATFORM MORE RICHER ... YOU ARE THE BEST.....WE WILL KILL IT...

  • @jigykat4436
    @jigykat4436 2 ปีที่แล้ว +3

    Respect to you brother. Keep up the good work 👏

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

    Exceptional explanation 👏👏👏

  • @RohanSharma-jh4ny
    @RohanSharma-jh4ny 2 ปีที่แล้ว +1

    No words for your compliments 🙇🙇🤗

  • @CoderA.D
    @CoderA.D 2 ปีที่แล้ว +2

    i solved it few days ago in hackerrank

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

    thank you bhaiya

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

    Thanks a lot for the question sir

  • @pragatii9054
    @pragatii9054 8 วันที่ผ่านมา

    Thank you

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

    we can also use the logic we use in palindrome, taking two pointers, return false if not match etc. And by this was we didn't use the space. GG

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

    Bhaiya isme se konse algo imp hai aur konse imp nahi hai from graph
    mtlb konse algo must do type hai
    1. bellman ford
    2. Floyd warshall
    3. traveling salesman
    4. flood fill algo
    5. graph coloring
    6. snake and game
    7. tarjans algo
    8. kosaraju algo
    9. bridge in graph
    10. articulate point

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

    Awesome brother!! So neat 👍

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

    your explanation is really great bhaiya. if possible ek dsa series (leetcode k questions) javascript me karao plz. I know javascript only. and javascript me dsa koi karata hi nhi.

  • @PAVANPATEL-yf4wf
    @PAVANPATEL-yf4wf 2 ปีที่แล้ว +1

    bhaiya kya aap block chain managment pe tutorial bana skte h kya?
    we need it

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

    Well explained!!! 😊
    You told on this video that we will see what happened when there are other characters alongwith brackets but maybe you missed. Please tell me how to deal with this?

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

      //add this line before for loop
      String valid = "({[]})";
      //inside loop
      char curr = str.charAt(i);
      if(valid.indexOf(curr) == -1) {
      //you can either "return false;" or
      //you can ignore the character with "continue;"
      //you can also use both, ex: when the character is number or operator you can ignore
      //else you can return false
      //depending on the problem statement
      }

  • @niladridas4286
    @niladridas4286 2 ปีที่แล้ว +3

    We can also use two increment operator count1 and count2 for the opening and closing parenthesis and atlast subtract both and if the value is zero string is valid else invalid

    • @AnujBhaiya
      @AnujBhaiya  2 ปีที่แล้ว +15

      This approach will fail for cases like this:
      )))(((

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

      @@AnujBhaiya hats off u bhaiya ur programming logic is excellent 🙏🙏🙏

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

    Awesome 🔥🔥🔥

  • @dhirajjadhao6392
    @dhirajjadhao6392 2 ปีที่แล้ว +3

    Here we go again

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

    i found this vdo really helpful🌻🌻

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

    Please explain differences between below two:
    "{ [ ] }" & "( [ ) ]"
    Here both have closing so why first one is true and second is false ?

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

      Hi, the opening and closing brackets should complement each other. Therefore, ( for ), [ for ] and { for }.
      I hope you understood.

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

      I had the same doubt, of the input string is ((]]{{[[}})).... Will this program work? Please let me know. Thanks!

  • @redsurge03
    @redsurge03 ปีที่แล้ว

    Awesome video sir, really helpful

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

    Great!!

  • @saritaprasad4295
    @saritaprasad4295 ปีที่แล้ว

    amazing

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

    acha pahele string ka size agar odd hua toh return false kar dena sahi hoga toh ?

  • @monishhs1253
    @monishhs1253 ปีที่แล้ว

    Thank you so much sir

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

    Nice explanation bhaiya❤❤

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

    Thank you bhaijaan 🌟🌟🌟🌟🌟

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

    @Anuj Bhaiya , Small enhancement... Can we add a condition as we know that if str.length() is odd then return false, as odd no. of brackets can't have its matches.

    • @RahulVerma-on7op
      @RahulVerma-on7op 2 ปีที่แล้ว +1

      No. Because order also matters

    • @sriramkukkadapu1049
      @sriramkukkadapu1049 ปีที่แล้ว

      @@RahulVerma-on7op Yes but if its odd we ll save so much of time & memory in returning output to user, it is just one efficient condition
      if length is even: above logics thought in video would come, but if its odd straight away we can return false.

  • @Shankar_-rl1cp
    @Shankar_-rl1cp ปีที่แล้ว +1

    class Solution { //Function to check if brackets are balanced or not. static boolean ispar(String x) { Stack st=new Stack(); st.push('a'); for(int i=0;i

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

    I have been following this amazing course!
    I just want to know that is there any platform where I can save all these codes and also the problems I solved in an organized way so that I can access them easily in future for revision and reference.

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

    Anuj bhaya we can also solve this problem using Catalan numbers also right

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

    Bhaiya .. when the string length is even then it's true and when it's odd it's false

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

      What about this case bro:- "(}{)"

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

      @@jeffkirchoff14 first the opening should come na!!

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

      First characters in the string should be open braces follwed by closed braces.. the thing is matching braces are there or not.. for example ((}} (this should be false ) I just proposed a condition of odd even it's not the full code

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

      I doesn't mean that it's gonna be true every time when it's even

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

      @@jeffkirchoff14 hmm... Right

  • @jhonsen9842
    @jhonsen9842 ปีที่แล้ว

    Bhai , Python ka Ek Series Banao With 150 Top Interview Problems. Which is not available in youtube in HIndi. Pura Desi bhasa mein.

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

    thanks bhaiya

  • @RahulSahu-hp1kz
    @RahulSahu-hp1kz 10 หลายเดือนก่อน

    Can i write the same code for the question Write a program in ‘C’ to check for balanced parenthesis in
    an expression using stack.

  • @ADITYA-rl8ub
    @ADITYA-rl8ub 2 ปีที่แล้ว

    Thanks big bro 👍👍

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

    @anuj bhaiya Bhaiya,can u please also provide the list of most important questions related to that topic which u covered in your video so that we can do more practice by ourselves,bcz over internet there are lots of questions and I am confused that time at that which question I have to solve .so It's request to u bhaiya ,if it will be possible please do for us🙏🙏🙏🙏

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

    Bhaiyya Catalan numbers theory samjha dijiyega

  • @user-tj3us8il6f
    @user-tj3us8il6f 2 ปีที่แล้ว

    @Anujbhaiya abhi course complete hone me kitna time lagega....

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

    May be it's personal but shashank mishra said that amazon never asked you to leave , bhaiya please clear us on this , is he lying ?

  • @ronitroy7028
    @ronitroy7028 ปีที่แล้ว

    can we do it by two pointer method , like one from 0th index and one from nth index and keep comparing till we reach middle or we don't find right pair

    • @ronitroy7028
      @ronitroy7028 ปีที่แล้ว

      no not for this {}() case my bad

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

    Pls provide code in python also

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

    Open parentheses ko pop kyu jab closing parentheses aata hai to ?????

  • @harshitshukla4532
    @harshitshukla4532 2 ปีที่แล้ว +3

    Have three variable br1=0, br2=0, br3=0. Whenever opening bracket do respective br++ ,
    When closing bracket do respective br--
    At end check all br==0 then balanced else unbalanced.

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

      This approach will fail for cases like these:
      )(][}{

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

      @@anujkumarsharma1013 will add an additional condition if br1= 0 and facing a closed bracket break the loop saying unbalanced...🙂

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

      Perfect then 🙌

    • @sriramkukkadapu1049
      @sriramkukkadapu1049 ปีที่แล้ว

      @@harshitshukla4532 I liked this approach its very simple and efficient no need of stack also :D
      public static boolean checkBalance(String s) {
      int br1=0,br2=0,br3=0;
      for(int i=0;i

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

    thanks bhayi

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

    Bhaiya please make a video on """how to learn Javascript"""

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

    Android development with kotlin course kb se aayega

  • @viralvibes1997
    @viralvibes1997 ปีที่แล้ว

    Mujhe English bilkul nhi aati, aur me bahot jyada introvert hu,
    Lekin main coding me bohot achha hu, ye problem main bina stack ke 3 line of code me kr liya.
    Mujhe job nhi mil rhi, bolate time me atakta hu, mujhe 1 question ke bad hi interview se bahar nikal dete hai.
    Mujhe kuch samajh nhi aa rha,
    Job nhi hai aur maa bimar hai

  • @ritavratdwivedi5286
    @ritavratdwivedi5286 ปีที่แล้ว

    What If we have a problem like this “}}]]))” this code will also return true in that case because stack will be empty only ?

  • @AkshayKumar-ee1sl
    @AkshayKumar-ee1sl 2 ปีที่แล้ว

    bhaiya meko na eak problem h
    main problem ko smjh kr uske solutions mind me calculte ke leta hu ki aaise aaise hona chahiye
    pr na code nhi likh pata
    kya kru!!

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

    Great

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

    Sir can you please make how we can make hanoi game in any language but my preferred language is PHP if you can make this video then it can help to understand.

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

    Add more questions like this🔥🔥

  • @SuriyaT3001
    @SuriyaT3001 ปีที่แล้ว

    what if we having an input like " } ( ) { " .Based on your algorithm output is false right?.. but here they are balanced or not .In my point of view they have a pair of { } ( ).Whether my question is reachable ?..

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

      as parenthesis they must have a opening bracket before closing

  • @ranselynigrel8714
    @ranselynigrel8714 ปีที่แล้ว

    Hi @anuj bhaiya , can below be considered as Balanced String
    {}[(]){}

    • @ronitroy7028
      @ronitroy7028 ปีที่แล้ว

      according to me no its not

  • @charukakkar6248
    @charukakkar6248 ปีที่แล้ว

    while writing the same code on leetcode , its showing so much errors

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

    Bhaiya, should I take a maths course for CP

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

    First First comment to thk h Like bhe karte jao yrr video, sir itne mhnat kar rahe h or aap like bhe nai kar rahe

  • @MrAnujbond
    @MrAnujbond ปีที่แล้ว

    Can anyone please confirm whether it is valid or not?
    String str = "))XYZ(("

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

    lot's of love to Anuj bhaiya and Love Babbar ❤️❤️❤️

  • @ArjunSingh-ex2hr
    @ArjunSingh-ex2hr 2 ปีที่แล้ว +1

    2nd Time...

  • @ArjunSingh-ex2hr
    @ArjunSingh-ex2hr 2 ปีที่แล้ว +1

    ❣❤

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

    beacause of this question i fail in my interview

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

    Is college syllabus enough to crack top MNC?

  • @Ayush-cc4ye
    @Ayush-cc4ye ปีที่แล้ว

    why not do this problem by placing a pointer at the starting of the string and one at the end and then bringing them towards the centre by iterations and comparing them at each iteration. if they don't match at any instance return false. this will take constant space and O(n) time

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

      suppose you have string like this
      ()(){{}()}
      then in this case start and end operator will not match and give us false but actually it,s true.

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

    First

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

    Anuj bhaiya.. please complete this DSA one till December 2021.. I will be passing out in 2022. I am fully dependent on this course.

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

    ❤❤❤❤

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

    Left Amazon 🙄

  • @NiteshSharma-wf1bk
    @NiteshSharma-wf1bk 2 ปีที่แล้ว

    👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻

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

    Leetcode program without error
    class Solution {
    public boolean isopening (char c){
    return c =='(' || c == '{' || c == '[' ;
    }
    public boolean ismatching (char a,char b){
    return (a =='(' && b ==')') || (a =='{' && b == '}') || (a =='[' && b == ']');
    }
    public boolean isValid(String s) {
    Stack str = new Stack();
    for ( int i = 0; i< s.length() ;i++){
    char cur = s.charAt(i);
    if( isopening (cur)){
    str.push (cur);
    }
    else {
    if(str.isEmpty ()) {
    return false ;
    }
    else if (!ismatching (str.peek() ,cur)) {
    return false;
    }
    else{
    str.pop();
    }
    }
    }
    return str.isEmpty();

    }
    }

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

    10th comment

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

    1st year students

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

    😍😍❣♥

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

    Python Solution:
    def isValid(self, s: str) -> bool:
    Que=[]
    Map={"(":")","[":"]","{":"}"}
    for i in s:
    if(i in Map):
    Que.append(i)
    else:
    if(len(Que)!=0 and Que[-1] in Map and Map[Que[-1]]==i):
    Que.pop()
    else:
    return False
    return len(Que)==0
    #Runtime: 34 ms, faster than 31.19% of Python3 online submissions for Valid Parentheses.
    #Memory Usage: 14.3 MB, less than 65.11% of Python3 online submissions for Valid Parentheses.

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

    import java.util.*;
    public class ValidParenthesis{
    static boolean isParenthesisMatching(String str){
    Stack s=new Stack();

    for(int i=0; i

    • @doubtgetout
      @doubtgetout ปีที่แล้ว

      Can you please write it for c++

    • @charukakkar6248
      @charukakkar6248 ปีที่แล้ว

      thankyou for this code

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

    Great

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

    First