✅[cpp || Self Explanatory, Intuitive & Easy to Understand || O(n) TC || O(n) SC]✅
Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n\nclass Solution {\npublic:\n    vector<int> lastVisitedIntegers(vector<string>& word
# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> lastVisitedIntegers(vector<string>& words) {\n        vector<int> ans, nums;\n        int cc = 0;\n        \n        for(string val : words){\n            int n = nums.size();\n            \n            if(val == "prev"){\n                cc++;\n                if(cc > n) ans.push_back(-1);  \n                else ans.push_back(nums[n - cc]);\n            }else{\n                cc = 0;\n                int number;\n                istringstream iss(val);\n                iss >> number;\n                nums.push_back(number);\n            }\n        } \n        return ans;\n    }\n};\n```
['C++']