We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
well this is the JavaScript solution but i'm not sure if i'm supposed to be using the Array shift and push if anybody else got a better idea please let me know thanks:
functionprocessData(input){//Enter your code herefunctionenqueue(queue,x){queue.push(x);}functiondeQueue(queue){queue.shift();}letdata=input.split('\n');data.shift();letqueue=[];for(leti=0;i<data.length;i++){letrow=data[i].split(" ");switch(Number(row[0])){case1:enqueue(queue,Number(row[1]));break;case2:deQueue(queue);break;case3:console.log(queue[0]);break;default:console.log(queue[0]);}}}
Cookie support is required to access HackerRank
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 →
well this is the JavaScript solution but i'm not sure if i'm supposed to be using the Array shift and push if anybody else got a better idea please let me know thanks: