Given a 0-indexed array of strings
words
wherewords[i]
is either a positive integer represented as a string or the string"prev"
.Start iterating from the beginning of the array; for every
"prev"
string seen inwords
, find the last visited integer inwords
which is defined as follows:
- Let
k
be the number of consecutive"prev"
strings seen so far (containing the current string). Letnums
be the 0-indexed array of integers seen so far andnums_reverse
be the reverse ofnums
, then the integer at(k - 1)th
index ofnums_reverse
will be the last visited integer for this"prev"
.- If
k
is greater than the total visited integers, then the last visited integer will be-1
.Return an integer array containing the last visited integers.
1 | class Solution { |