A queue with two stacks

A few years ago, during a job interview for Google, a friend got the following challenge: “implement a queue using two stacks”. I found it an interesting challenge, so I decided to give it a thought (for the inverse problem, check the next post). Before you keep reading, think about how you would approach this challenge. … Done? Let’s begin with a brief review on stacks and queues. Stacks and queues A stack is a collection of elements based on the concept of Last In First Out (LIFO): the last added element is the first to leave.

Means, Medians and Images

Measures of central tendency (mean, median, mode, etc.) are some of the first concepts we learn in any basic statistics course. Such concepts are illustrated with several examples, such as: the mean height of the students in the class (or more sensitive information such as age or weight), or the mean/median salary of a company. It is essential to understand these concepts to better understand the world around us. In this post, however, the goal is not to explain neither the concepts, nor why they are important, but to answer the question: what does it have to do with computer science?