Easy java solution
\nclass Solution {\n    public List<Integer> lastVisitedIntegers(List<String> list) {\n        List<Integer> num=new ArrayList<>();\n        List<Integer> res=n
```\nclass Solution {\n    public List<Integer> lastVisitedIntegers(List<String> list) {\n        List<Integer> num=new ArrayList<>();\n        List<Integer> res=new ArrayList<>();\n        int c=0;\n        for(int i=0;i<list.size();i++)\n        {\n           if(list.get(i).equals("prev"))\n           {\n               if (c < num.size())\n               {\n                   res.add(num.get(num.size()-1-c));\n               }\n                else\n                {\n                res.add(-1);\n                }\n               c++;\n           }\n                else {\n                     int nums = Integer.valueOf(list.get(i));\n                    num.add(nums);\n                        c = 0;\n                    }           \n            \n        }\n        return res;\n    }\n}\n```
['Java']