Given a 0-indexed array of strings
wordswherewords[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 inwordswhich is defined as follows:
- Let
kbe the number of consecutive"prev"strings seen so far (containing the current string). Letnumsbe the 0-indexed array of integers seen so far andnums_reversebe the reverse ofnums, then the integer at(k - 1)thindex ofnums_reversewill be the last visited integer for this"prev".- If
kis 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 { |