JAVA | Easy code
Code\n\nclass Solution {\n    public List<Integer> lastVisitedIntegers(List<String> words) {\n        List<Integer> ans = new ArrayList<>();\n        List<Strin
# Code\n```\nclass Solution {\n    public List<Integer> lastVisitedIntegers(List<String> words) {\n        List<Integer> ans = new ArrayList<>();\n        List<String> digits = new ArrayList<>();\n        int k = 0;\n        for (String word : words) {\n            if (word.equals("prev")) {\n                k++;\n                ans.add((digits.size() - k < digits.size() && digits.size() - k >= 0) ? Integer.parseInt(digits.get(digits.size() - k)) : -1);\n            } else {\n                digits.add(word);\n                k = 0;\n            }\n        }\n        return ans;\n    }\n}\n```
['Java']