✅ Best 100% || Only Python || Simple Explanation ✅|| Easy to understand 🔥🔥🔥🔥
\uD83D\uDD3C IF YOU FIND THIS POST HELPFUL PLEASE UPVOTE \uD83D\uDC4D\n\n# Complexity\n- Time complexity: O(n) in the worst case due to the single loop iteratin
# \uD83D\uDD3C IF YOU FIND THIS POST HELPFUL PLEASE UPVOTE \uD83D\uDC4D\n\n# Complexity\n- Time complexity: `O(n)` in the worst case due to the single loop iterating through the `input` list.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: `O(n)` in the worst case due to the potential size of the `seen` and `ans` lists.\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 = []\n        ans = []\n        k = 0\n        for i in range(len(nums)):\n            if nums[i] > -1 :\n                seen.insert(0, nums[i])\n            else:\n                if k < len(seen) and nums[i - 1] == -1:\n                    k += 1\n                    ans.append(seen[k - 1])\n                elif k < len(seen):\n                    k = 1\n                    ans.append(seen[0])\n                else:\n                    ans.append(-1)\n        return ans\n```\n\n### \uD83D\uDD3C If you found my solution and information helpful, I would greatly appreciate your upvote, as it would motivate me to continue sharing more solutions. \uD83D\uDD3C\n![upvote.jpg](https://assets.leetcode.com/users/images/a13ab0b5-6f2b-4804-87d2-999b78e64297_1712149472.8021562.jpeg)
['Array', 'Simulation', 'Python3']