Duplicate Brackets | Solution

Поделиться
HTML-код
  • Опубликовано: 27 окт 2024

Комментарии • 137

  • @bachelorbecomescomics1053
    @bachelorbecomescomics1053 3 года назад +8

    I haven't come across a better explanation than this. Came after watching 2 other videos and reading one solution approach also

  • @dheerajkhushalani2619
    @dheerajkhushalani2619 3 года назад +10

    amazing teacher.. full Indian style teaching.. thank u

  • @niteshrawat576
    @niteshrawat576 9 месяцев назад +2

    Great explanation by sir, one correction I would like to add, is to only push "(" and operators in the stack and not the characters. The reason is (a+ (b)) is a redudant case. Happy coding! :)

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

    One of the best teachers on RUclips nicely explained

  • @roymedia9683
    @roymedia9683 3 месяца назад

    this is my first video ever seen in your channel you are GOAT(Greatest of all teachers )

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

    I will be commenting on those videos which I have watched, in order to mark it. Great explanantion.....

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

    samaj geya aur mein ho geya mala mala....thanks for the great explanation.

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

    greatest of all time teaching

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

    Sir..nice explanation!. But, for "()", we need to add some additional checks.

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

      jo kabhi khula hi nai uske liye kya hi khojega bhai

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

    Sir your teaching style is awesome👍👍👍👍

  • @sangameshkulkarni8303
    @sangameshkulkarni8303 4 года назад +3

    Very nice explanation sir !!
    But...I think ,u missed this (a) kind of test case...!!

  • @akshatmathur3446
    @akshatmathur3446 4 года назад +5

    You are just awesome sir !! 👌👌

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

    We have to look for a condition. at line 15 if stack is empty other wise it will throw EmptyStackException

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

    Thank you sir. Very helpfull video...

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

    Sir aap log toh bhot aaram se Amazon , Facebook ya Google ke interview fod ke aa jate honge 😍😍

  • @ShatanshPatel
    @ShatanshPatel 5 часов назад

    a+b) ye karne pr exception dedega empty stack exception

  • @aayushsingh5614
    @aayushsingh5614 8 месяцев назад

    Happy to do the solution by myself

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

    Great explanation as always

  • @jaydipkansara1
    @jaydipkansara1 4 года назад +4

    What about string "(a)"? This should return 1(redundant braces). But with this algo, it will return 0(no redundant braces).
    Can you please explain how do we handle this case?

    • @Pepcoding
      @Pepcoding  4 года назад +1

      they are not redundant. they have an expression inside.

    • @jaydipkansara1
      @jaydipkansara1 4 года назад +8

      @@Pepcoding Hi sir, thanks for replying. I tried this solution on interviewbit. But this case "(a)" is failing there.not sure how to handle this

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

      class Solution:
      def braces(self, A):
      stack=[]
      for i in A:
      if i==')':
      flag=True
      top=stack[-1]
      stack.pop()
      while(top!='('):
      if(top=='+' or top=='-' or top=='*' or top=='/'):
      flag=False

      top=stack[-1]
      stack.pop()
      if flag==True:
      return 1
      else:
      stack.append(i)
      return 0

    • @harshsingh3550
      @harshsingh3550 9 месяцев назад

      @@jaydipkansara1 You can use sir's approach. Just one change should be made, i.e., use a flag variable before the while loop, that can check if there are any operators in between two brackets or not. Initialize the flag to false, and even after coming out of the while loop, if the flag is false, this means that there are no operators. So, we can understand that here redundancy is present.

  • @shraddhabahal7403
    @shraddhabahal7403 4 года назад +1

    Sir, but it's failing cases like (a) where it should be false it's showing true

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

    what would be the output for (a).. i think your code will accept this. since there is duplicity in this input, there is no need to put parenthesis for single character

    • @nivealokhande2153
      @nivealokhande2153 Год назад +1

      Broo itss okay as per sample test case too. Duplicacy will be for ((a))

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

    The NDOS website is not running and not able to open it.

  • @037_sayedramishali7
    @037_sayedramishali7 4 года назад +2

    Sir agar ham space bhi use karte hai string mai
    Space bhi push hoga kya stack pe??
    Aur agar stack mai (,space hoga to peek se ( milega ya space??

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

    Sir this code is failing in gfg practice compiler.

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

    Sir aap kis ide ko use krte h ??

  • @shivammehta9661
    @shivammehta9661 3 года назад

    very nice explanation

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

    Is this question available on NADOS?

  • @prashantranjan3777
    @prashantranjan3777 4 года назад +1

    Hi In pep coding IDE I am submitting Python code, its not giving output.Can you please share the format which needs to submit. Do we need to define class or direct method we can add in python.
    Thank you for nice explanation.

    • @Pepcoding
      @Pepcoding  4 года назад +1

      I will ask the dev team to check python compiler

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

    This solution wont work in case of (a+b+(c)) (on gfg) but perfect explaination you yourself get to the solution after hitting that case

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

    good sir..

  • @harshitsharma1880
    @harshitsharma1880 3 года назад

    but sir this is not working for (a+(b)/c)
    it should print true
    but its's printing false

  • @Sachinkumar-ou5vu
    @Sachinkumar-ou5vu 4 года назад

    Nice teaching sir 🙏🙏🙏✍️🙏🙏✍️

  • @rakhijha4065
    @rakhijha4065 3 года назад +1

    Sir what about if the case is ((a+b)(c+d))

    • @shubamgoswami
      @shubamgoswami 3 года назад

      i am also confuse in that case

    • @shubamgoswami
      @shubamgoswami 3 года назад

      ok i got the answer that is redudant because ((a+b)(c+d)) == (a+b)(c+d)we dont need outer brackets thats ehy this is correnct we get the same anwer without the outer bracs
      more examples down
      Input:
      ((a+b))
      (a+(b)/c)
      (a+b*(c-d))
      Output:
      Yes
      Yes
      No
      Explanation:
      1. ((a+b)) can reduced to (a+b), this Redundant
      2. (a+(b)/c) can reduced to (a+b/c) because b is
      surrounded by () which is redundant.
      3. (a+b*(c-d)) doesn't have any redundant or multiple
      brackets.

  • @akashkhandelwal-altruistic5363
    @akashkhandelwal-altruistic5363 3 года назад

    Nice explanation sir

    • @Pepcoding
      @Pepcoding  3 года назад

      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like our efforts, we request a review
      g.page/Pepcoding/review?rc
      You can subscribe to our channel here
      ruclips.net/user/Pepcodingabout?view_as=subscriber

  • @SudhanshuKumar-lp1nr
    @SudhanshuKumar-lp1nr 4 года назад

    @Pepcoding Sir you're not checking cases for (a) or (+)

    • @adityagupta1805
      @adityagupta1805 3 года назад

      it giving correct answers for these cases

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

    what about a+(b)+c

  • @AmanKumar-kz1rn
    @AmanKumar-kz1rn 4 года назад

    sir inh dono line mai difference kya hota hai
    String str = scn.next();
    String str = scn.nextLine();

    • @Pepcoding
      @Pepcoding  4 года назад +19

      beta jaise a b c
      hai to next aapko sirf a dega
      nextLine a b c dega poora

    • @JaiSagar7
      @JaiSagar7 3 года назад +4

      next reads only a word
      while nextLine reads whole line

  • @anishmondal7310
    @anishmondal7310 3 месяца назад

    (b+c-d+(c)) in this case the logic will be wrong...please try again

  • @SudhanshuKumar-lp1nr
    @SudhanshuKumar-lp1nr 4 года назад +2

    Sir you're not checking cases for (a) or (+)

  • @Anonymous-ue1wp
    @Anonymous-ue1wp 2 года назад

    sir apke course me question to he lkn oops aur baki chhote chhote concepts gayab he

  • @thisisdenish
    @thisisdenish 3 года назад +1

    what if we want to check duplicates inside sub expression??

    • @thisisdenish
      @thisisdenish 3 года назад +1

      okay, I found the answer for this question.
      while popping until opening bracket found, we will count the number of operators(+,-,*,/).
      if the number of operators is 0, then we can say that it has duplicates inside the sub expression.
      i.e.((a)+b)

    • @abhigyannayak4151
      @abhigyannayak4151 3 года назад +1

      @@thisisdenish Or you can just counter the characters inside it..if its < 2..its redundant

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

    Can anyone tell me why we are using return when this is clearly not a function why not use break to get out the loop ?

    • @learnfrompast
      @learnfrompast 9 месяцев назад

      after printing true , it will return from the main function . so it won't execute any further statement

  • @LetszGoo
    @LetszGoo 3 года назад

    Sir you are awesome

    • @Pepcoding
      @Pepcoding  3 года назад

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @ved7678
    @ved7678 3 года назад

    sir the code fail for (a+(b)/c)

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

    sir strings ki video aai hi ni hai to thodi dikkat ho rhi hai, agr ho to upload kr dijiyega.
    Thankyou.

    • @Pepcoding
      @Pepcoding  4 года назад

      han yar, DP karne lag gae. DP -> Graphs -> Strings -> OOPs -> Time and Space
      abhi yahan se kijie
      www.pepcoding.com/resources/data-structures-and-algorithms/strings-and-stringbuilder

    • @Python_DSA_Journey
      @Python_DSA_Journey 4 года назад +1

      @@Pepcoding Thankyou so much sir..bhut khushi ho rhi hai thankyou thankyou thankyou...

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

      arey, love you love you love you. Bhavuk kyu ho rha hai bro

    • @Python_DSA_Journey
      @Python_DSA_Journey 4 года назад

      @@Pepcoding 😁😁😅

    • @SudhanshuKumar-lp1nr
      @SudhanshuKumar-lp1nr 4 года назад

      Sir you're not checking cases for (a) or (+)

  • @xoxoxo7313
    @xoxoxo7313 8 месяцев назад

    BESTTTTT

  • @believeinpractical3930
    @believeinpractical3930 4 года назад

    Nice

  • @fashionvella730
    @fashionvella730 3 года назад

    i was think the same login but in a different way

  • @JaiSagar7
    @JaiSagar7 3 года назад

    Thankyou sir

  • @ritikshrivastava9442
    @ritikshrivastava9442 3 года назад

    sir your code not work for this
    (a+(b)/c) this test case is failing.
    since there is no use of () for b .
    bool RedundantBrackets(string s)
    {
    stack st;
    int count;
    for(int i=0; i

  • @letsdoeverythinginoneweek9398
    @letsdoeverythinginoneweek9398 3 года назад

    phela wala test case ma isliya false aaya kyu ki vo jo plus ha na vo bhi pop ho gaya kyu ki vo bracket ka beech ma ha isliya dusra vala fail hua kyu ki vo plus pop nahi ho payaaaaa

  • @willturner3440
    @willturner3440 3 года назад +4

    May be your code fails in (a+(b) /c)
    Plz reply sir

  • @vinayakagarwal1118
    @vinayakagarwal1118 4 года назад

    Your DSA series is amazing sir..Can you also list the questions of leetcode for Second step that is for level up..

    • @Pepcoding
      @Pepcoding  4 года назад +1

      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like my efforts, I request a review
      g.page/Pepcoding/review?rc
      2nd step series will come here
      www.pepcoding.com/resources/data-structures-and-algorithms-in-java-levelup/

    • @vinayakagarwal1118
      @vinayakagarwal1118 4 года назад

      @@Pepcoding Thanks a lot Sir. I have dropped my review about the course..

  • @037_sayedramishali7
    @037_sayedramishali7 4 года назад +1

    Sir
    (a + b) +((c + d))
    Ye fail ho rha hai ek case c++ mai ismai aapne spaces diye hai spaces hatake pass ho rha hai can u please chk it🙏

    • @Elon-musk-007
      @Elon-musk-007 4 года назад

      Right!

    • @ankurkumar8465
      @ankurkumar8465 4 года назад

      Bro it's simple if input[i]==' ',then don't push it into the stack.

    • @pranjalmittal1973
      @pranjalmittal1973 3 года назад

      @@ankurkumar8465 still not getting the correct ans!

    • @ankurkumar8465
      @ankurkumar8465 3 года назад

      @@pranjalmittal1973 If input[i] = ' ' i. e. space then simply continue... don't do anything in this case.

    • @pranjalmittal1973
      @pranjalmittal1973 3 года назад

      @@ankurkumar8465 yeah, i did this, still it did not pass all the test cases.

  • @gautamnegi6868
    @gautamnegi6868 3 года назад

    Sir ye beech mai return lga k program terminate kese hora h, plz reply anyone

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

    This will return trur for - (), but there is no duplicate brackets here

  • @willturner3440
    @willturner3440 3 года назад +1

    Want to buy your course for placements

    • @Pepcoding
      @Pepcoding  3 года назад

      Beta, you can contact us on 01140194461 Or you can write to us at contact@pepcoding.com

    • @shubhamgupta5819
      @shubhamgupta5819 3 года назад

      Son, I can give you my id for 12k only (non negotiable -__-)

  • @shinobiwolf8133
    @shinobiwolf8133 3 года назад

    Sir the code will fail for "(a)" test case.

    • @revaanmishra
      @revaanmishra 3 года назад

      use this condition:
      if (A[i] == '(' && A[i + 2] == ')')
      return 1;

  • @ANKITAYADAV-ll6sv
    @ANKITAYADAV-ll6sv 3 года назад

    Sir for () a+b it gives true.but we are talking about duplicate bracket

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

      Lemme check it and go through it once again.

    • @raj-nq8ke
      @raj-nq8ke 3 года назад +2

      obiously it will give true cause its a duplicate bracket

  • @SanjayGupta-sb8wo
    @SanjayGupta-sb8wo 3 года назад

    Sir humne isme wo question jis ko hum test kar rhe the uska input kaha par diya?

    • @Pepcoding
      @Pepcoding  3 года назад

      Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.

  • @apoorv7361
    @apoorv7361 3 года назад

    (a+(b)/c) on this test case i think the given solution will not work please check

    • @Pepcoding
      @Pepcoding  3 года назад

      Gimme some time, will check and correct it, if it wrong.

  • @vinayakagarwal1118
    @vinayakagarwal1118 4 года назад

    sir appke first input mein spaces hain input: (a + b) + ((c + d)). So isliye mera first test case fail ho rha hai..

    • @Pepcoding
      @Pepcoding  4 года назад +1

      aap logic mei handle kar dijie ki space ignore ho jaien.

    • @vinayakagarwal1118
      @vinayakagarwal1118 4 года назад

      @@Pepcoding Thank you sir for your videos.. These are really helpful..

    • @harshtamkiya8505
      @harshtamkiya8505 4 года назад +1

      Incase if you are using sc.next() use sc.nextLine(). This worked for me.

    • @vinayakagarwal1118
      @vinayakagarwal1118 4 года назад

      @@harshtamkiya8505 Thanks but actually I am doing in c++ so this will not work 😅

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

    sir how an i get the solution in cpp

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

      For all your doubts refer to nados.pepcoding.com
      Also stay tuned on our Instagram .

  • @mahendersharma5972
    @mahendersharma5972 4 года назад

    Sir video or dal dena java ki

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

    int checkRedundancy(string s) {
    // code here
    stack st;
    int i=0;
    while(i

  • @itsyashh1308
    @itsyashh1308 4 года назад

    Ek Test case fail ho rha hai sir
    (a+b)+((a+b)) espe

  • @kamyakamya1874
    @kamyakamya1874 2 месяца назад

    Java Solution
    import java.util.* ;
    import java.io.*;
    import java.util.ArrayList;
    public class Solution
    {
    public static boolean findRedundantBrackets(String s)
    {
    // Write your code here.
    Stack stack = new Stack();
    for(int i =0;i

  • @rituraj6056
    @rituraj6056 3 года назад

    1:string=(a+b)+(c+d)
    2:string=(a+b*c*(d*f)+g)
    could someone plz tell me about the o/p of this i/p?
    I think o/p must be true

    • @rituraj6056
      @rituraj6056 3 года назад

      @pepcoding sir what is the difference between redundant brackets and duplicate brackets?

  • @letsdoeverythinginoneweek9398
    @letsdoeverythinginoneweek9398 3 года назад

    KUCH TEST CASE SAHI NAHI HA SAHI OUTPUT PA BHI WRONG ANSWER AARA

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

    public static boolean checkRedundantBrackets(String expression) {
    int n=expression.length();
    Stack st=new Stack();
    int i=0,count=0;
    for(i=0;i

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

      sign up on nados.io
      You will get better experience with precisely organised content

  • @Vikas-ye1hx
    @Vikas-ye1hx 2 года назад

    if string is "))))))))"

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

      good test case, just check if first char is ')' then return true.

  • @mahendersharma5972
    @mahendersharma5972 4 года назад +3

    10 rs ki Pepsi apna bhai sexy 😁😁😁😁

  • @sunnykakrani7830
    @sunnykakrani7830 4 года назад

    #include
    using namespace std;
    int main()
    {
    string s;
    cin>>s;
    stackst;
    int c=0;
    for(int i=0;i

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

    maal hai ya maal nahi hain :p