You are viewing a single comment's thread. Return to all comments →
Barely able to pass without the timeout error after trying multiple times:
function processData(input) { let s1 = [], s2 = [] let inputs = input.split('\n') for (let i = 1; i < inputs.length; i++) { let arr = inputs[i].split(' ') switch (arr[0]) { case '1': { s1.push(arr[1]) break } case '2': { while (s1.length > 0) s2.push(s1.pop()) s2.pop() while (s2.length > 0) s1.push(s2.pop()) break } case '3': { console.log(s1[0]) break } } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Queue using Two Stacks
You are viewing a single comment's thread. Return to all comments →
JS
Barely able to pass without the timeout error after trying multiple times: