Simple Python 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:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\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 = deque()\n        ans = []\n        cnt = 0\n        n = len(seen)\n\n        for idx, num in enumerate(nums):\n            if num != -1:\n                seen.appendleft(num)\n                n += 1\n            else:\n                if idx > 0 and nums[idx - 1] == -1:\n                    cnt += 1\n                else:\n                    cnt = 1\n                if cnt <= n:\n                    ans.append(seen[cnt - 1])\n                else:\n                    ans.append(num)\n        \n        return ans\n```
['Python3']