We can have a basic parenthesis matching algorithm were we use a stack and match each opening and closing braces. Now, along with an opening brace we can also store its index and while matching the closing brace, we can find duplicates if the matches are consecutive. i.e.; if the closing braces are consecutive and the indices of their matching opening braces are consecutive, then they are duplicates.