visitedIntegers to keep track of the integers seen so far.result to store the last visited integers for each 'prev'.prevCount to 0 to count consecutive 'prev' strings.words array.
a. If the current string is an integer, reset prevCount to 0 and push the integer onto the visitedIntegers stack.
b. If the current string is 'prev', increment prevCount.
i. If prevCount is greater than the size of visitedIntegers, append -1 to result.
ii. Otherwise, append the integer at index size - prevCount from the visitedIntegers stack to result.result list.