Detailed C++ solution || O(n) complexity || Easy and Straight-forward approach
\n# Approach\n I am traversing through the array words.\n    -If the array element is not "prev", it must be a number.I am converting the string "2" to integer 
\n# Approach\n I am traversing through the array **words**.\n    -If the array element is not **"prev"**, it must be a number.I am **converting** the string **"2"** to integer **2** using **stoi()** function.\n    - I have a **temp** vector which stores the converted number.\n    - I am keeping a **count** variable which will be **0** initially. This **increases** by 1 everytime I get a "**prev**". When I **don\'t** get a **"prev"**, I initialise count **back to 0**.\n    - Now, if **count <=temp.size()**, my desired number is **temp[temp.size()-count]** which will be pushed into my final ans vector.(*dry run to understand better*);\n    - if **count >temp.size()** it means there are more **"prev"** than numbers and thus, we **push_back(-1)** into ans.\n\n# Complexity\n- Time complexity:\n**O(n)**\n\n- Space complexity:\n**O(n)**\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> lastVisitedIntegers(vector<string>& words) {\n        vector<int>temp;\n        vector<int>ans;\n        int count=0;\n        int n=words.size(),num;\n        for(int i=0;i<words.size();i++){\n            if(words[i]!="prev"){\n                count=0;\n                num=stoi(words[i]);\n                temp.push_back(num);\n            }\n            else{\n                count++;\n                if(count<=temp.size()){\n                    ans.push_back(s[temp.size()-count]);\n                }\n                else {\n                    ans.push_back(-1);\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['Array', 'C++']