C++ SOLUTION
Intuition\n\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Tim
# Intuition\n![images.jpeg](https://assets.leetcode.com/users/images/89ef68ed-cdae-443e-a6ea-20f5c1515fd7_1721110819.9197898.jpeg)\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> lastVisitedIntegers(vector<int>& nums) \n    {\n        int cnt = 0;\n        deque<int>dq, ans;\n        for(auto val:nums)\n        {\n            if(val == -1) \n            {\n                ans.push_back(cnt < dq.size() ? dq[cnt] : -1);\n                cnt++;\n                continue;\n            }\n            cnt = 0;\n            dq.push_front(val);\n        }\n        return vector<int>(ans.begin(), ans.end());\n    }\n};\n```
['C++']