I know I’ve to use stacks. It is similar to balanced parentheses. But I’m not getting what are the conditions to be used.
Not getting the approach
follow this approach
push everything into stack except ‘)’ when u encounter ‘)’ store the top of stack and then pop it
now run a while loop till u hit ‘(’ inside the loop, pop the elements of the stack and increase a counter initialised to zero, if the counter at the end of the while loop>0 then it is not duplicate else it is duplicate
this is because if counter is zero then a ‘(’ is encountered before any other element which indicates redundancy
this is the code for it too,
do try before jumping right to it
if your doubt is solved, please mark it as resolved