Skip to content

Instantly share code, notes, and snippets.

@developersoom
Created November 29, 2018 07:39
Show Gist options
  • Save developersoom/34154ee6f89e33d83a646a2127b4a867 to your computer and use it in GitHub Desktop.
Save developersoom/34154ee6f89e33d83a646a2127b4a867 to your computer and use it in GitHub Desktop.
ATaleofTwoStacks
function processData(input) {
let arr = input.split('\n');
let queue = [];
for (let i = 1; i < arr.length; i++){
if (Number(arr[i][0]) === 1) {
let value = arr[i].slice(2,arr[i].length);
queue.push(value);
}
if (Number(arr[i]) === 2) {
queue.shift();
}
if (Number(arr[i]) === 3) {
console.log(queue[0])
}
}
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});
process.stdin.on("end", function () {
processData(_input);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment