Leetcode in Java && Oracle
422 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2021-11-05_17-43-17.png
33.9 KB
#N1441. Build an Array With Stack Operations

problem link

#solution
class Solution {
public List<String> buildArray(int[] target, int n) {
ArrayList<String> stack=new ArrayList<String>();
int x=0;
for(int i=1;i<=n && x<target.length; i++){
stack.add("Push");
if(target[x]==i) x++;
else stack.add("Pop");
}

return stack;
}
}