Easy beginner Friendly Solution🔥
\n\n# Code\n\nclass Solution {\n    public List<Integer> lastVisitedIntegers(int[] nums) {\n        List<Integer> seen=new ArrayList<>();\n        List<Integer>
\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        for(int i=0;i<nums.length;i++){\n            if(nums[i]>0){\n                seen.add(0,nums[i]);\n            }\n            else{\n                if(i!=0 && nums[i-1]!=-1){\n                    k=1;\n                }\n                else{\n                    k++;\n                }\n                \n                if(k<=seen.size()){\n                    ans.add(seen.get(k-1));\n                }\n                else{\n                    ans.add(-1);\n                }\n            }\n        }\n        return ans;\n    }\n}\n```
['Java']