Straightforward Solution || 0ms || Beats 100% users
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
```cpp []
class Solution {
public:
    vector<int> lastVisitedIntegers(vector<int>& nums) {
        int n=nums.size();
        vector<int> seen;
        vector<int> ans;
        int k=0;
        for(int i=0;i<n;i++){
            if(nums[i]!=-1){
                k=0;
                seen.insert(seen.begin(),nums[i]);
            }else{
                k++;
                if(k<=seen.size()){
                    ans.push_back(seen[k-1]);
                }else
                    ans.push_back(-1);
            }

        }

        return ans;
    }
};
```
['C++']