Queue using Two Stacks

  • + 0 comments

    My Solution in Javascript also works with TypeScript:

    function processData(input) {

    const query = input.split('\n').slice(1)
    
    const answer = []
    
    for(let i = 0; i < query.length; i++) {
        if(query[i].charAt(0) === '1') {
            const [index, number] = query[i].split(' ')
            answer.push(number) 
        }
        if(query[i].charAt(0) === '2') {
            answer.shift()
        }
    
        if(query[i].charAt(0) === '3') {
            console.log(answer[0])
        }
    }
    

    }