Build an Array With Stack Operations - LeetCode Weekly Contest 188

preview_player
Показать описание
1441. Build an Array With Stack Operations - LeetCode.
In this video:
- seeing when to "push" vs "push"+"pop"
- implement our solution by looping over target
- optimize by pre-calculating the required number of operations
----------------------------------
Try it yourself here
#StayHome and code #WithMe
Рекомендации по теме
Комментарии
Автор

In this video:
- seeing when to "push" vs "push"+"pop"
- implement our solution by looping over target
- optimize by pre-calculating the required number of operations

daose
Автор

Please do more of these weekly contests ! You are a blessing for me and my uni mates ! Thank you 😍

pahehepaa
Автор

please fix your mic can't hear you properly

afzal
Автор

It won't clear all the testcases. Below is modified solution which clears all the testcases

class Solution {
public List<String> buildArray(int[] target, int n) {
List<String> s = new ArrayList<String>();

int input = 1;

for(int i:target){
if(input != i){
while(input != i){
s.add("Push");
s.add("Pop");
input++;
}
s.add("Push");
input++;
}
else{
s.add("Push");
input++;
}
}
return s;
}
}

bhawik
join shbcf.ru