last visited integers
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```\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        int p=0;\n        for(int i:nums)\n        {\n        if(i>0)\n        {\n            seen.addFirst(i);\n            p++;\n        }\n        else\n        {\n         if(k<seen.size() && p==k){\n         ans.add(seen.get(k));\n         k++;\n         p=k;\n         }\n         else if(p!=k && k<seen.size())\n         {\n          k=0;\n          ans.add(seen.get(k));\n          k++;\n          p=k;\n         }\n         else\n         {\n          ans.add(-1);\n         }\n        }\n        }\n        return ans;\n    }\n}\n```
['Java']