C++ || Brute Force ||
Intuition\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 
# Intuition\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<string>& words) {\n        int n=words.size();\n        vector<int>ans;\n        vector<int>temp;\n        int count=0;\n        int t=0;\n        for(int i=0;i<n;i++){\n            if(words[i]!="prev"){\n                temp.push_back(stoi(words[i]));\n                t++;\n                count=0;\n            }else{\n                count++;\n                vector<int>temp2;\n                for(auto x: temp){\n                    if(x!=-1)\n                        temp2.push_back(x);\n                }\n                reverse(temp2.begin(),temp2.end());\n                if(((count<=t))and (count-1)>=0)\n                     ans.push_back(temp2[count-1]);\n                else ans.push_back(-1);\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']