Java Solution with 1ms runtime and 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 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```java []\nclass Solution {\n    public List<Integer> lastVisitedIntegers(int[] nums) {\n        List<Integer> seen=new ArrayList<>();\n        List<Integer> ans=new ArrayList<>();\n        int k=0;\n        for(int i:nums){\n            if(i==-1){\n                k++;\n                if(seen.size()<k){\n                    ans.add(-1);\n                }\n                else{\n\n                    ans.add(seen.get(k-1));\n                }\n            }\n            else{\n                seen.addFirst(i);\n                k=0;\n            }\n        }\n        return ans;\n    }\n}\n```
['Java']