via Loop
Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\ncsharp []\npublic class Solution {\n    public IList<int> LastVisitedIntegers(int[]
# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```csharp []\npublic class Solution {\n    public IList<int> LastVisitedIntegers(int[] nums) {\n        int n = nums.Length;\n        IList<int> result = new List<int>();\n        IList<int> seen = new List<int>();\n        int k = 0;\n\n        for (int i = 0; i < n; i++) {\n            if (nums[i] != -1) {\n                seen.Add(nums[i]);\n                k = 0;\n            }\n            else {\n                k++;\n\n                if (seen.Count >= k) {\n                    result.Add(seen[seen.Count - k]);\n                }\n                else {\n                    result.Add(-1);\n                }\n            }\n        }\n\n        return result;\n    }\n}\n```
['Array', 'C#']