Queues Interview Questions

In this section, we'll look at how queues work and how to use them in your interviews and in writing programs.

Queues work by storing data items in the order they arrive, and removing or processing them in the same order. This is known as first-in, first-out (FIFO) processing. They have many different uses, but developers often find them especially useful when it comes to doing some work in order, or in the background while keeping the main program/thread unblocked. They're very similar to stacks, which are LIFO (last-in, first-out) structures.

Section Menu

How do I use this section?

1. LESSON

Understanding the Queue Data Structure and Its Implementations

A queue is a collection of items whereby its operations work in a FIFO - First In First Out manner. The two primary operations associated with them are enqueue and dequeue. Lesson Objectives: At the end of this lesson, you will be able to: Know what the queue data str...

2. CHALLENGE

Bottom Left Node Value

Assume we're using a binary tree in writing a video game via Binary Space Partitioning. We need to identify the bottom left leaf, that is-- the leftmost value in the lowest row of the binary tree. <img src="https://...

3. CHALLENGE

Max Per Level

Given a binary tree, write a method to return an array containing the largest (by value) node values at each level. In other words, we're looking for the max per level. So for instance, given the following binar...

4. CHALLENGE

Traverse in a Zig Zag

Here's a fun one: can you write a method to return the nodes of a binary tree in a zig zag level order? It should return a multi-dimensional array of...

5. CHALLENGE

Two Stack Queue

Building a Queue with Two Stacks: A Challenge in Engineering Elegance The Queue with Stacks In this challenge, your task is to implement a queue using two stacks. While many programming languages offer queues through arrays or lists, we're restricting our approach to only utilize stacks. The end result should b...

6. CHALLENGE

Climbing the Word Ladder

Imagine two words placed at the two ends of a ladder. Can you reach one word from another using intermediate words as rings of the ladder? Each successive or transition word has a difference of only one letter from its predecessor, and must belong to a provided dictionary. Can we achieve this using the shortest possible number of r...