Interviewing with Facebook — Phone Screen Questions Part 1

Image for post

Last spring, I had a chance to interview with Facebook. I didn?t end up landing the job, but I did manage to get past the first few phone screens. That means they were willing to pay to fly me out to New York City, where I got to stay in a swanky hotel where I worked on programming problems on my iPad.

All told, it was a good experience even though it wasn?t a fit (at the time).

If you?re thinking about working at Facebook, you should know a few things. First of all, their stack is mostly Objective-C. They do a bit of Swift, but they have some pretty good reasons not to.

You should also know that Facebook?s interview questions are designed to get at a deep understanding of the programming language you will be working with. No understanding, no job (I suppose that says a lot about me ?).

Anyway, I do what I can. Like I said, I managed to get past the first phone screen so I must have some level of what they?re looking for.

I?d like to transfer some of that knowledge to you, in hopes that one of you will get further along than I did.

The first interview question

Given that you have passed the initial phone screening with a recruiter, you will at some point be asked to schedule a second phone screen with someone more technical. This person will likely ask you to hop on a shared programming environment where you will answer some questions with a little more substance to them.

As I understand it, the first question is designed to weed out the unwashed masses. It?s one of those basic ?hey do you know about sets and arrays?? type questions.

If you can?t answer that question, they probably end the call on the spot. That?s my guess at least. I answered it correctly, so I?m not sure about that.

The question

Given an array of strings like the following, how do you remove the duplicates?

I can already hear the grumbling from the audience. At this point, most of you would think to create a new array, iterate through the names array, and only add a name to the new array if the name isn?t already contained within your array.

Your totally valid solution might look like this

And this works. At this point, the person on the phone will ask you what order the elements will be in. You?ll say ?Oh it?s Bob, Jill, Alice? and you would be right.

But although this question appears to focus on arrays, it is secretly designed to test if you know about this other thing called a set.

Well, do you?

What is a Set?

A set is a collection of any type of element (think generics) where none of the elements are duplicated and the order of the elements is not important.

Did you catch the thingy about no duplication? That?s the point to be emphasized.

It means you can do things like this

If you print the contents of the nonDuplicatedString variable, you?ll get the same ?Bob, Jill Alice? like before.

Of course this works for removing duplicates, but it gets even better than that. You can do all of the duplicate removal in just one line of code (and four easy payments of $19.99).

For reference, you don?t even need the fancy declaration saying you are creating a set of type String. The following works just fine too.

Under the hood, the Foundation Set type will do all of the duplicate removal for you. Just pass in an array of hashable stuff, and the duplicates are gone!

Image for post

No muss. No fuss. No greasy clogged toilet. Now you can move onto the next interview question.

What?s next?

I encourage you to follow along my interview with Facebook. The next part of the series will show you the secret underbelly of a common type you typically use in Swift.

Interviewing with Facebook ? Phone Screen Questions Part 2


No Responses

Write a response