Python | O(N) time, O(1) space
Code\n\nclass Solution:\n    def lastVisitedIntegers(self, words: List[str]) -> List[int]:\n        res = []\n        prv = e = 0\n        for i, w in enumerate
# Code\n```\nclass Solution:\n    def lastVisitedIntegers(self, words: List[str]) -> List[int]:\n        res = []\n        prv = e = 0\n        for i, w in enumerate(words):\n            if w == "prev":\n                res.append(int(words[e - 1 - prv]) if e - 1 - prv >= 0 else -1)\n                prv += 1\n            else:\n                words[e] = w\n                e += 1\n                prv = 0\n        return res\n```
['Python3']