Python Iterative Solution (without reversing): same stack logic as recursive
What I didn\'t like reading all these iterative solutions is that they are completely different logic than the recursive solution. If you\'re asked in an interv
What I didn\'t like reading all these iterative solutions is that they are completely different logic than the recursive solution. If you\'re asked in an interview a question like this, you should be prepared to transfer your exact recursive logic to iterative logic because in an interview you probably aren\'t going to have the time or stroke of luck to think of a cute change in logic on the spot and recursive solutions are often way easier to find.\n\nThis solution returns each value in the exact way the recursive solution does by using 2 stacks, one for the nodes being looked at as well as their corresponding index for iterating through their children, just like the recursive solution would do. I probably should\'ve combined the node and index into one object and just used one stack, but it is what it is.\n\nEasier to read if you simply recognize stack[-1] is just stack.peek(), which Python doesn\'t implement.\n\nSuggestions for improvement welcome.\n\n```\nclass Solution(object):\n    def postorder(self, root):\n        """\n        :type root: Node\n        :rtype: List[int]\n        """\n        if not root:\n            return []\n\t\t\t\t\t\t\n        stack, counters, retList = [root], [0], []\n        \n        while len(stack) != 0:\n\t    #To English: while the current top of the stack has an unseen child\n            while counters[-1] < len(stack[-1].children):\n\t\t# Add that child to the top of the stack, with a new corresponding counter to the other stack\n                stack.append(stack[-1].children[counters[-1]])\n                counters.append(0)\n\t    # If the current top of the stack has reached the end of its children list, then we pop it, it\'s done\n            retList.append(stack.pop().val)\n\t    # need to pop its counter as well\n            counters.pop()\n\t    # and increment the counter of the next top of the stack to begin that search\n            if len(counters) != 0:\n                counters[-1] += 1\n            \n        return retList\n```
[]