C++ implementation easy
\n\n# Code\n\nclass Solution {\npublic:\n    vector<int> lastVisitedIntegers(vector<string>& words) {\n        vector<int> ans;\n        vector<int> prev;\n    
\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> lastVisitedIntegers(vector<string>& words) {\n        vector<int> ans;\n        vector<int> prev;\n        for(int i=0;i<words.size();i++){\n            if(words[i]=="prev"){\n                int noOfPrev=1;\n                int j=i-1;\n                while(j>=0 && words[j]=="prev"){\n                    noOfPrev++;\n                    j--;\n                }\n                int n=prev.size();\n                if(n-noOfPrev>=0){\n                    ans.push_back(prev[n-noOfPrev]);\n                }\n                else ans.push_back(-1);\n            }\n            else{\n                prev.push_back(stoi(words[i]));\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']