Super Reduced String

  • + 0 comments

    using stack

    def superReducedString(s):
        # Write your code here
        s = [i for i in s]
        stack = []
        for i in s:
            if not stack:
                stack.append(i)
            else:
                if i==stack[-1]:
                    stack.pop(-1)
                else:
                    stack.append(i)
        if stack:
            return ''.join(stack)
        else:
            return 'Empty String'