This is not working for some test cases

You are getting wrong answer for the sample test case only. First try to get correct answer for that. Dry run your code on the input.

my code is giving duplicates if there is some a+(b) but in the question this is not considered as duplicate . please edit my code for the necessary changes

Simply push all characters when it is not a ‘)’. When you get a ‘)’, if the top is ')" => display duplicate. Else, pop all characters till you get a ‘)’ and then pop this as well at the end.