Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Tó Rugain
Wrong concept in this solution

Tó Rugain

Nov 28, 2025

Since you are using a stack, and the session clearly talk about a stack, at the end of this solution you are doing a JOIN with a stack. A stack is a structure that only can be iterated with pop() method (you only know the last element), and join takes the first position of a interable, till the last position, breaking the concept of a stack. This solution follows the real concept of a stack def removeDuplicates(self, s):         # ToDo: Write Your Code Here.         stack = []         result = []         for pos in range(len(s)):             if stack and s[pos] == stack[-1]:                 stack.pop()                 continue             stack.append(s[pos])                 while stack:             result.append(stack.pop())                 result.reverse()         return "".join(result)

0

0

Comments
Comments