2899. Last Visited Integers
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
from typing import List

class Solution:
    def lastVisitedIntegers(self, nums: List[int]) -> List[int]:
        seen = []  # Stack to hold the visited positive integers
        ans = []   # Result list to store the answers
        k = 0       # Count of consecutive -1s

        for num in nums:
            if num == -1:
                k += 1  # Increment consecutive -1 count
                if k <= len(seen):
                    ans.append(seen[k-1])  # Get the k-th element from seen
                else:
                    ans.append(-1)  # Not enough elements in seen
            else:
                seen.insert(0, num)  # Prepend the positive number to seen
                k = 0  # Reset the count of consecutive -1s
        
        return ans

```
['Python3']