---
# System prepended metadata

title: 1441. Build an Array With Stack Operations
tags: [Leetcode, Easy]

---

# 1441. Build an Array With Stack Operations
###### tags: `Leetcode` `Easy`
Link: https://leetcode.com/problems/build-an-array-with-stack-operations/
## Code
```java=
class Solution {
    public List<String> buildArray(int[] target, int n) {
        List<String> ans = new ArrayList<>();
        int idx = 0;
        int num = 1;
        while(idx<target.length){
            ans.add("Push");
            if(target[idx]==num){
                idx++;
            }
            else{
                ans.add("Pop");
            }
            num++;
        }
        return ans;
    }
}
```