[C++] Simulation
Intuition\n Describe your first thoughts on how to solve this problem. \n- Keep tracking the visited integers\n- Count the number of consecutive prev strings se
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- Keep tracking the visited integers\n- Count the number of consecutive `prev` strings seen so far\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- store the visited integers in `nums`\n- Let `k` be the number of consecutive `prev` strings seen so far\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    // time/space: O(n)/O(n)\n    vector<int> lastVisitedIntegers(vector<string>& words) {\n        vector<int> nums;\n        vector<int> result;\n        int k = 0;\n        for (const string& word : words) {\n            if (word == "prev") {\n                k++;\n                if (k > nums.size()) result.push_back(-1);\n                else result.push_back(nums[nums.size() - k]);\n            }\n            else {\n                k = 0;\n                nums.push_back(stoi(word));\n            }\n        }\n        return result;\n    }\n};\n```
['Array', 'Simulation', 'C++']