Best Java Solution || Beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public List<Integer> lastVisitedIntegers(List<String> arr) {\n\n        List<Integer> nums = new ArrayList<>();\n        List<Integer> ans = new ArrayList<>();\n\n        int count = -1;\n\n        for(int i=0; i<arr.size(); i++){\n            if(arr.get(i).equals("prev")){\n                if(count==-1) ans.add(-1);\n                else ans.add(nums.get(count--));\n            }else{\n                int a = 0;\n                String s = arr.get(i);\n                for(int j=0; j<s.length(); j++){\n                    a *= 10;\n                    a += (s.charAt(j)-\'0\');\n                }\n                count = nums.size();\n                nums.add(a);\n            }\n        }\n        return ans;\n    }\n}\n```
['Java']