C++ Solution
\n# Code\ncpp []\nclass Solution {\npublic:\n    vector<int> lastVisitedIntegers(vector<int>& nums) {\n        vector<int>ans;\n        vector<int>seen;\n      
\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<int> lastVisitedIntegers(vector<int>& nums) {\n        vector<int>ans;\n        vector<int>seen;\n        int k = -1;\n        for(int i = 0; i < nums.size(); i++){\n            if(nums[i] > 0) {\n                seen.push_back(nums[i]);\n                k = seen.size() - 1;\n            }\n            else{\n                if(k >= 0)\n                    ans.push_back(seen[k--]);\n                else\n                    ans.push_back(-1);\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']