Submission beat 100% of other submissions' runtime.
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```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 = 1;\n        for (int num : nums) {\n            if (num > 0) {\n                seen.add(0, num);\n                k = 1;\n            } else {\n                if (k <= seen.size()) {\n                    ans.add(seen.get(k - 1));\n                    k++;\n                } else {\n                    ans.add(-1);\n                }\n            }\n        }\n        return ans;\n    }\n}\n```
['Java']