# ☕ Message Queues

### An awesome guide on Message Queues. Plus, what was it like to work under Steve Jobs in the 2000s as a Software Engineer at Apple? Also, an answer to yesterday's coding interview question.

Hey Guys,

Interviewing.io is a *fantastic* resource I wanted to share with you all.

You can **book realistic mock interviews with senior FAANG engineers** who will give you **detailed and actionable feedback** on exactly what you need to work on.

Mastering algorithms on LeetCode and system design on SystemsExpert is great, but they don’t prepare you for the pressure and stress that comes from an actual interview setting.

The best part?

**You don’t pay anything until you’re hired.**

Check them out here.

*Special thanks to Interviewing.io for sponsoring Quastor Daily. I’m a user of the service!*

# Tech Snippets

**The Big Little Guide to Message Queues**

An awesome blog post on Message Queues

Covers things like

What is a Message Queue and why are they necessary

Delivery Mechanisms and the different delivery guarantees

Ordering and Parallelism

Popular message queues like AWS SNS & SQS, Google Pub/Sub, Redis Streams, etc.

**Working at Apple in the 2000s under Steve Jobs**

An awesome podcast with David Shayer, a Software Engineer at Apple (he was there from 2001 to 2015).

There’s some interesting discussion on David’s work on file systems (HFS+) and his work with the iPod.

David was actually hired by Tony Fadell, who was in charge of the iPod and oversaw hardware and firmware for the iPhone.

# Interview Question

Given two arrays of integers, compute the pair of values (one value in each array) with the *smallest* (non-negative) difference.

Return the difference.

`Example`

`Input - [1, 3, 15, 11, 2], [23, 127, 235, 18, 9]`

`Output - 2`

`Explanation - The difference between 11, 9`

*We’ll send a detailed solution tomorrow, so make sure you move our emails to primary, so you don’t miss them!*

**Gmail users**—move us to your primary inbox

**On your phone?**Hit the 3 dots at the top right corner, click "Move to" then "Primary"**On desktop?**Back out of this email then drag and drop this email into the "Primary" tab near the top left of your screen

**Apple mail users**—tap on our email address at the top of this email (next to "From:" on mobile) and click “Add to VIPs”

# Previous Solution

**As a refresher, here’s the last question**

Given a positive integer *n*, write a function that computes the number of **trailing** zeros in *n*!

`Example`

`Input - 12`

`Output - 2`

`Explanation - 12! is 479001600`

`Input - 900`

`Output - 224`

`Explanation - 900! is a big ass number`

**Here’s the question in LeetCode.**

**Solution**

This question requires a bit of basic number theory.

Recall that

`6! = 1 * 2 * 3 * 4 * 5 * 6 = 720`

From this, we can see that the trailing 0 comes from `2 * 5`

in our factorial equation.

We can generalize this to all factorials. Whenever we have a `2 * 5`

in our factorial, then we will get a trailing zero.

This also applies to multiples 2 and 5. Whenever we have a multiple of 2 being multiplied by a multiple of 5, that will add a trailing zero. Or if we have a number that is a multiple of both 2 and 5.

Another way of thinking of this is breaking down each individual number in our factorial equation by its factors. Then we count the number of 2s and 5s and that will be the number of trailing zeros.

`6! = 1 * 2 * 3 * (2 * 2) * 5 * (3 * 2)`

We have four 2s but only one 5, so the number of trailing zeros is 1.

Multiples of 2 are more common than multiples of 5, so we can actually just count the number of 5s in our factorization break down and return that as the number of trailing 0s. We’ll always have enough 2s to match the 5s.

We can count the number of multiples of 5 by dividing `n`

by 5.

However, this will undercount the number of 5s in our factorization when we have a number that has *multiple* 5s in it’s factorization.

For example, `25 = 5 * 5`

So, we have two 5s in that factorization, but when we divide n by 5, we’re only counting 25 as a single 5.

Therefore, we have to repeat the process for all the powers of 5 and divide n by those powers so that we don’t undercount them.

Here’s the Python 3 code.

```
def trailingZeroes(n: int) -> int:
zeros = 0
power = 1
while 5**power <= n:
zeros += n // 5**power
power += 1
return zeros
```

**Want more practice with real FAANG software engineers?**

Check out Interviewing.io!

You don’t have to pay anything until you get that job at FAANG!

## Create your profile

## Only paid subscribers can comment on this post

Log in## Check your email

For your security, we need to re-authenticate you.

Click the link we sent to , or click here to log in.