Build an Array With Stack Operations
Given an array target
and an integer n
. In each iteration, you will read a number from list = {1,2,3..., n}
.
Build the target
array using the following operations:
Push: Read a new element from the beginning
list
, and push it in the array.Pop: delete the last element of the array.
If the target array is already built, stop reading more elements.
You are guaranteed that the target array is strictly increasing, only containing numbers between 1 to n
inclusive.
Return the operations to build the target array.
You are guaranteed that the answer is unique.
Example 1:
Example 2:
Example 3:
Example 4:
Constraints:
1 <= target.length <= 100
1 <= target[i] <= 100
1 <= n <= 100
target
is strictly increasing.
Last updated