easy solution using deque  😍❤️‍🔥
if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n\nclass Solution {\npublic:\n    vector<int> lastVisitedIntegers(vector<int>& nums) \n    {\n   
# if it\'s help, please up \u2B06 vote! \u2764\uFE0F\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```
['Array', 'Queue', 'Simulation', 'C++']