Simple and clear python3 solution | One pass + stack
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n# Co
# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n``` python3 []\nclass Solution:\n    def lastVisitedIntegers(self, words: List[str]) -> List[int]:\n        stack = []\n        position = -1\n        result = []\n        for elem in words:\n            if elem == \'prev\':\n                if position == -1:\n                    result.append(-1)\n                else:\n                    result.append(stack[position])\n                    position -= 1 \n            else:\n                stack.append(int(elem))\n                position = len(stack) - 1\n        \n        return result\n```
['Stack', 'Simulation', 'Python3']