o(n) solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# 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```\nclass Solution:\n    def lastVisitedIntegers(self, nums: List[int]) -> List[int]:\n        seen, ans, cur = deque(), [], 0\n        for num in nums:\n            if num != -1:\n                seen.appendleft(num)\n                cur = 0\n                continue\n\n            cur += 1\n            ans.append(-1 if cur > len(seen) else seen[cur - 1])\n        return ans\n```
['Python3']