Leetcode 1441: Build an Array With Stack Operations

In this Leetcode problem we are given an integer n representing the list {1, 2, ..., n}, and an array int[] target. We are going to assume we have a stack and we are pushing 1, 2, ... and popping number so that we can arrive to target as a result. The question is, in what order should we push and pull so that we arrive at target?

Problem statement