Kotlin O(n) solution
\n# Code\nkotlin []\nclass Solution {\n  fun lastVisitedIntegers(nums: IntArray): List<Int> {\n        var seen = LinkedList<Int>()\n        var ans = ArrayList
\n# Code\n```kotlin []\nclass Solution {\n  fun lastVisitedIntegers(nums: IntArray): List<Int> {\n        var seen = LinkedList<Int>()\n        var ans = ArrayList<Int>()\n        var last = 0;\n        for (i in nums.indices) {\n            var current = nums[i]\n            if (last > 0 && current > 0) {\n                last = 0;\n            } else if (current.equals(-1)) {\n                last++\n                if (last > seen.size) {\n                    ans.add(-1)\n                } else {\n                    ans.add(seen.get(last-1))\n                }\n            }\n            if (current > 0) seen.addFirst(current)\n        }\n        return ans;\n    }\n}\n```
['Array', 'Kotlin']