easyArraySimulation 0 views
Last Visited Integers
Given an integer array nums where nums[i] is either a positive integer or -1.
Given an integer array nums where nums[i] is either a positive integer or -1. We need to find for each -1 the respective positive integer, which we call the last visited integer.
To achieve this goal, let's define two empty arrays: seen and ans.
Start iterating from the beginning of the array nums.
Return the array ans.
Example 1
Input: nums = [1,2,-1,-1,-1]
Output: [2,1,-1]
Explanation: Start with seen = [] and ans = [] .
Example 2
Input: nums = [1,-1,2,-1,-1]
Output: [1,2,1]
Explanation: Start with seen = [] and ans = [] .
Constraints
- 1 <= nums.length <= 100
- nums[i] == -1 or 1 <= nums[i] <= 100
Hints
Companies
No companies reported yet.
Discussion
Sign in to join the discussion.
Loading discussion...
Test results
No test cases yet.