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

Поделиться
HTML-код
  • Опубликовано: 29 сен 2021
  • Hey guys, In this video, We're going to solve another very famous Interview Problem called - Parentheses Matching Problem.
    code: www.geeksforgeeks.org/check-f...
    Practice questions: www.interviewbit.com/courses/...
    🥳 Join our Telegram Community:
    Telegram channel: telegram.me/realanujbhaiya
    Telegram group: telegram.me/dsa_one
    🚀 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

  • @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 💪.

  • @jigykat4436
    @jigykat4436 2 года назад +3

    Respect to you brother. Keep up the good work 👏

  • @ExotikTravels
    @ExotikTravels 2 года назад +1

    Bahut hard-working ho bhai aap toh ... maine toh shuru hi kiya hai DS padhna ... aapka level super se upar hai ...this video is helpful... aur hindi mein hone ki wajah se ekdum acche se samajh aaya ... mujhse interview mein poocha gaya tha yeh question ... aaj samajh aaya ki kya solution tha iska ... thanks!!!

  • @dheerajkhushalani2619
    @dheerajkhushalani2619 2 года назад +16

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

  • @RohanSharma-jh4ny
    @RohanSharma-jh4ny 2 года назад +1

    No words for your compliments 🙇🙇🤗

  • @krishnarajput5008
    @krishnarajput5008 2 года назад +2

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

  • @ashokanumandla1280
    @ashokanumandla1280 2 года назад +1

    Awesome brother!! So neat 👍

  • @rishavrox007
    @rishavrox007 2 года назад +2

    Thanks a lot for the question sir

  • @shivangisrivastava1158
    @shivangisrivastava1158 2 года назад +2

    Exceptional explanation 👏👏👏

  • @neeshusharma5889
    @neeshusharma5889 Год назад

    i found this vdo really helpful🌻🌻

  • @redsurge03
    @redsurge03 Год назад

    Awesome video sir, really helpful

  • @vashishthsharma4411
    @vashishthsharma4411 2 года назад +1

    thank you bhaiya

  • @deepjyotidebnath4122
    @deepjyotidebnath4122 2 года назад

    Nice explanation bhaiya❤❤

  • @abhishekarora437
    @abhishekarora437 2 года назад +1

    Awesome 🔥🔥🔥

  • @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-RUclipsR..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 RUclips PLATFORM MORE RICHER ... YOU ARE THE BEST.....WE WILL KILL IT...

  • @kunalkheeva
    @kunalkheeva 2 года назад +1

    Great!!

  • @monishhs1253
    @monishhs1253 11 месяцев назад

    Thank you so much sir

  • @ADITYA-rl8ub
    @ADITYA-rl8ub 2 года назад

    Thanks big bro 👍👍

  • @rohitmaurya5931
    @rohitmaurya5931 2 года назад

    thanks bhaiya

  • @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 🔥❤️

  • @saritaprasad4295
    @saritaprasad4295 Год назад

    amazing

  • @CoderA.D
    @CoderA.D 2 года назад +2

    i solved it few days ago in hackerrank

  • @vishnups9793
    @vishnups9793 2 года назад

    thanks bhayi

  • @prathameshpatkar4172
    @prathameshpatkar4172 2 года назад

    Thank you bhaijaan 🌟🌟🌟🌟🌟

  • @vinaysahanivinaysahani6904
    @vinaysahanivinaysahani6904 2 года назад

    Great

  • @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🙏🙏🙏🙏

  • @mousumikundu2680
    @mousumikundu2680 Год назад

    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

  • @i_nishantjain
    @i_nishantjain Год назад

    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.

  • @tejasukalkar2199
    @tejasukalkar2199 2 года назад +4

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

  • @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

  • @ashishkumarsrivastav9106
    @ashishkumarsrivastav9106 2 года назад

    Bhaiyya Catalan numbers theory samjha dijiyega

  • @dhirajjadhao6392
    @dhirajjadhao6392 2 года назад +3

    Here we go again

  • @himanshuladva8127
    @himanshuladva8127 2 года назад

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

  • @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

  • @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 Год назад

      //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
      }

  • @avijitmondal2497
    @avijitmondal2497 2 года назад

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

  • @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.

  • @ayushdas17
    @ayushdas17 2 года назад

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

  • @deepjyotidebnath4122
    @deepjyotidebnath4122 2 года назад +1

    Add more questions like this🔥🔥

  • @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.

  • @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.

  • @user-tj3us8il6f
    @user-tj3us8il6f 2 года назад

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

  • @hardcodeandroid
    @hardcodeandroid 2 года назад

    Android development with kotlin course kb se aayega

  • @ArjunSingh-ex2hr
    @ArjunSingh-ex2hr 2 года назад +1

    ❣❤

  • @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

  • @vaishalimishra6261
    @vaishalimishra6261 2 года назад +2

    Pls provide code in python also

  • @ankitdubey6813
    @ankitdubey6813 2 года назад

    ❤❤❤❤

  • @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!

  • @RahulSahu-hp1kz
    @RahulSahu-hp1kz 9 месяцев назад

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

  • @lokendrasingh9780
    @lokendrasingh9780 2 года назад

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

  • @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

  • @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 ?

  • @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!!

  • @ranselynigrel8714
    @ranselynigrel8714 Год назад

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

  • @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 ?

  • @NiteshSharma-wf1bk
    @NiteshSharma-wf1bk 2 года назад

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

  • @pmahaur962
    @pmahaur962 6 месяцев назад

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

  • @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 года назад +16

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

    • @krishnakantahirwar6418
      @krishnakantahirwar6418 2 года назад +2

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

  • @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

  • @charukakkar6248
    @charukakkar6248 Год назад

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

  • @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 10 месяцев назад

      as parenthesis they must have a opening bracket before closing

  • @MrAnujbond
    @MrAnujbond Год назад

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

  • @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 ❤️🙏

  • @codingknowledge7328
    @codingknowledge7328 2 года назад

    beacause of this question i fail in my interview

  • @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

  • @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.

  • @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

  • @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.

  • @kapilsingh2816
    @kapilsingh2816 2 года назад

    Left Amazon 🙄

  • @ArjunSingh-ex2hr
    @ArjunSingh-ex2hr 2 года назад +1

    2nd Time...

  • @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();

    }
    }

  • @igaming_
    @igaming_ 2 года назад

    1st year students

  • @shivammaurya5464
    @shivammaurya5464 2 года назад +1

    Is college syllabus enough to crack top MNC?

  • @sakura_blue_berry8117
    @sakura_blue_berry8117 2 года назад +1

    First

  • @samirkumarsanu6947
    @samirkumarsanu6947 2 года назад +1

    😍😍❣♥

  • @ankursolanki886
    @ankursolanki886 2 года назад

    10th comment

  • @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

  • @himanshu1304
    @himanshu1304 2 года назад

    Great

  • @UtkarshGangwar7052
    @UtkarshGangwar7052 2 года назад +1

    First