function processData(input) { class Node {...} class Stack {...} const inputArray = input.split('\n'); let stackIn = new Stack(); let stackOut = new Stack(); let valArry, result = ''; for(let i=1; i<=inputArray[0]; i++) { valArry = inputArray[i].split(' '); switch(valArry[0]) { case '1': enqueue(valArry[1]); break; case '2': dequeue(); break; case '3': result += `${front()}\n`; break; } } function enqueue(val) { stackIn.push(val); } function dequeue() { if(stackOut.size === 0) { while(stackIn.size > 0) { let item = stackIn.pop(); stackOut.push(item); } } stackOut.pop(); } function front() { if(stackOut.size === 0) { while(stackIn.size > 0) { let item = stackIn.pop(); stackOut.push(item); } } return stackOut.peek(); } return process.stdout.write(result); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Discussion on: Daily Coding Puzzles - Nov 11th - Nov 16th
Replies for: Thursday - Queue from two stacks (Hacker Rank Medium) Complete the put, pop, and peek methods in the editor below. They must perform the actions ...
For further actions, you may consider blocking this person and/or reporting abuse