Java 100% Faster Solution
Complexity\n- Time complexity: O(N)\n- Space complexity: O(N)\n\n# Code\n\nclass Solution {\n    public List<Integer> lastVisitedIntegers(int[] nums) {\n       
# Complexity\n- Time complexity: O(N)\n- Space complexity: O(N)\n\n# Code\n```\nclass Solution {\n    public List<Integer> lastVisitedIntegers(int[] nums) {\n        List<Integer> seen = new ArrayList<>();\n        List<Integer> ans = new ArrayList<>();\n        int negOne = 0;\n        for (int n: nums) {\n            if (n > 0) {\n                seen.add(n);\n                negOne = 0;\n            } else {\n                negOne++;\n                if (negOne <= seen.size()) {\n                    ans.add(seen.get(seen.size() - negOne));\n                } else {\n                    ans.add(-1);\n                }\n            }\n        }\n        return ans;\n    }\n}\n```
['Java']