❇ last-visited-integers Images👌 🏆O(N)❤️ Javascript🎯 Memory👀73%🕕 ++Explanation✍️🔴🔥✅💪🙏👉
Time Complexity: O(N)\uD83D\uDD55\nSpace Complexity: O(N)\n\n\nvar lastVisitedIntegers = function (nums) {\n    let seenIndex = -1;  // \uD83D\uDCCC Tracks the 
**Time Complexity: O(N)\uD83D\uDD55\nSpace Complexity: O(N)**\n\n```\nvar lastVisitedIntegers = function (nums) {\n    let seenIndex = -1;  // \uD83D\uDCCC Tracks the index of the last seen element in `seen`\n    let seen = [];       // \uD83D\uDCDD Stores all the elements that have been visited\n    let ans = [];        // \u2728 The array where we\'ll store our results\n\n    for (const iterator of nums) {    // \uD83D\uDD04 Loop through each element in the `nums` array\n        if (iterator === -1) {        // \u26A0\uFE0F If the current element is `-1`...\n            ans.push(seen[seenIndex] || -1); // \u21A9\uFE0F Add the last visited number to `ans`\n            seenIndex -= 1;           // \uD83D\uDD19 Move to the previous element in `seen`\n        } else {                      // \u2705 If it\'s a valid number...\n            seen.push(iterator);      // \uD83D\uDCE5 Add it to the `seen` array\n            seenIndex = seen.length - 1;  // \uD83D\uDD04 Update `seenIndex` to point to the new last element\n        }\n    }\n\n    return ans;  // \uD83C\uDF89 Return the final result\n};\n\n```\n\n\nPlease upvote \uD83D\uDCAA if like\n![image](https://assets.leetcode.com/users/images/3ca14ca6-e2d2-47ec-9aed-0ab2a4ad9767_1727117871.0956626.png)\n
['JavaScript']