Build an Array With Stack Operations LeetCode solution in C++
1class Solution {2public:3vector<string> buildArray(vector<int> &target, int n) {4vector<string> ans;5int l = target.size(), count = 0,6ind = 0; // ind is index of the target array78for (int i = 1; i <= n; i++) {9if (count == l) break;10if (target[ind] != i) {11ans.push_back("Push");12ans.push_back("Pop");13} else {14ans.push_back("Push");15count++;16ind++;17}18}19return ans;20}21};