SIMPLE AND STRAIGHT APPROACH 
IntuitionThe problem requires us to track the last visited integers based on the sequence of positive integers and -1 markers. Every time we encounter a positiv
# Intuition
The problem requires us to track the last visited integers based on the sequence of positive integers and `-1` markers. Every time we encounter a positive integer, we should prepend it to a list (`seen`). When encountering `-1`, we need to retrieve the corresponding last visited integer based on the number of `-1`s seen so far.

# Approach
1. **Use a list (`seen`)** to store all encountered positive integers in a stack-like order (most recent at the front).
2. **Use a counter (`k`)** to track the number of `-1`s seen so far.
3. **Iterate through `nums`**:
   - If a positive integer is found, **insert it at the front** of `seen` and **reset `k` to 0**.
   - If `-1` is found:
     - If `k` is within `seen`'s bounds, append the `k`-th last visited integer to `ans` and **increment `k`**.
     - If `k` exceeds the number of stored elements, append `-1` to `ans`.
4. **Return the `ans` array**, which contains the required sequence of last visited integers.

# Complexity
- **Time complexity:**  
  - **Insertion at the front of `seen`** takes **O(n)** in the worst case (since `vector::insert()` is costly at the front).
  - Iterating through `nums` is **O(n)**.
  - Overall, the worst-case complexity is **O(n²)** due to `insert()`, but if we optimize with a deque, it could be improved to **O(n)**.

- **Space complexity:**  
  - **O(n)** for storing elements in `seen` and `ans`, leading to an **O(n)** space requirement.


# Code
```cpp []
class Solution {
public:
    vector<int> lastVisitedIntegers(vector<int>& nums) {
        vector<int> seen;
        vector<int> ans;
        int k = 0;

        for (int i = 0; i < nums.size(); i++) {
            if (nums[i] != -1) {
                seen.insert(seen.begin(), nums[i]);  
                k = 0;  
            }
            else if (k < seen.size()) {
                ans.push_back(seen[k]);
                k++;
            }
            else {
                ans.push_back(-1);
            }
        }
        return ans;
    }
};

```
['Array', 'Simulation', 'C++']