Easy to understand Solution || Explained
Complexity\n- Time complexity: O(n) \n\n- Space complexity: O(1)\n\n# Code\n\nclass Solution {\npublic:\n    vector<int> lastVisitedIntegers(vector<string>& wor
# Complexity\n- Time complexity: $$O(n)$$ \n\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> lastVisitedIntegers(vector<string>& words) {\n        vector<int> ans;\n        vector<int> integers;\n        int prev = 0;\n        for(int i=0; i<words.size(); i++)\n        {\n            if(words[i] != "prev")\n            {   //push all the integers in a vector\n                integers.push_back(stoi(words[i]));\n                prev = 0;\n            }\n            else\n            {\n                prev++; //count consecutive "prev" occurences\n                int n = integers.size(); \n                int insert = n >= prev ? integers[n-prev] : -1; //get previous kth element, if it exists\n                ans.push_back(insert);\n            }\n        }\n     return ans;\n    }\n};\n```
['C++']