Simple C++ Solution ✅
Approach\n Describe your approach to solving the problem. \nKeep a count for no of previous till now,\nreset it to 0 whenever you encounter a number.\nKeep a ar
# Approach\n<!-- Describe your approach to solving the problem. -->\nKeep a count for no of previous till now,\nreset it to 0 whenever you encounter a number.\nKeep a array to store the numbers you encounter encounter \n->when encountering a prev \n    1. increment the p_count.\n    2. check if p_count is greater than nums size then push -1 to ans.\n    3. else push the p_count element from last in nums to ans.\n\n-> when encountering a number\n    1. convert the string to num by stoi and push it to nums.\n    2. reset the p_count to 0.\n\n# Complexity\n- Time complexity: $$O(N)$$\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> lastVisitedIntegers(vector<string>& words) {\n        int n = words.size();\n    \n        vector<int> ans;\n        vector<int> nums;  \n        int p_Count = 0; \n\n        for (int i = 0; i<n; i++) {\n            string word = words[i];\n            if (word == "prev") {\n                p_Count++;\n                if (p_Count > nums.size()) {\n                    ans.push_back(-1);\n                } else {\n                    ans.push_back(nums[nums.size() - p_Count]);\n                }\n            } else {\n                int num = stoi(word);\n                nums.push_back(num);\n                p_Count = 0;\n            }\n        }\n\n        return ans;\n    }\n};\n```
['C++']