class Solution: def makeGood(self, s: str) -> str: stack = [] for c in s: if stack and c.lower() == stack[-1].lower() and c != stack[-1]: stack.pop() else: stack.append(c) return "".join(stack) Complexity Time: O(1) Space: O(n)