Two weeks ago I did the phone screen for Pinterest, and I still haven't heard anything, so let me post the question while I wait.
The recruiter told me beforehand that this round would just be one coding question, and at the time I felt pretty relaxed — I figured forty-five minutes for one problem would be plenty either way. Turns out I was being naive.
The question was this: given a set of elevators, each with a current floor and a status of up, down, or idle, plus a passenger's floor and the direction they want to go, return the index of the nearest elevator that can pick them up, or -1 if none can. The rule is that an idle elevator can pick up anyone, but a moving elevator can only pick up a passenger who is on the way and going the same direction. The edge case is when the elevator and the passenger are on the same floor but going opposite directions — that elevator can't take them.
This part went fine. I ran a few test cases myself after writing it and they all checked out, and the interviewer didn't say anything. Then he said let's look at the follow-up, and I checked the clock and saw I still had twenty minutes left, so I thought I had this in the bag.
The follow-up: all the elevators start out idle, and you're given each elevator's starting floor. Then n people board one after another, and for each person you're given their direction, their starting floor, and the time they get on. The question is which elevator the last person ends up riding.
I genuinely had never seen anything like this. I thought about it for a bit and said: set up a global clock starting at zero, go through the people in time order, and for each person scan through all the elevators; if that person's boarding time doesn't match the current global time, shift each elevator's floor by the difference, then call the function from part one. The interviewer said I was on the right track and told me to just write pseudocode, I didn't need to actually write the code.
Then time was up.
Thinking back on it, that follow-up was basically a whole new question in its own right — it just got tacked onto the first one so it didn't look as scary. My mind went a little blank at the time, and I could tell my explanation was noticeably less smooth than it had been for the first part.
I followed up with the recruiter once in between and never heard back, so I don't know if no news is bad news here.
I wanted to ask everyone: for a phone screen where the follow-up was only talked through and never actually coded, does the interviewer saying "on the right track" count as a pass or not? I honestly have no idea.
Discussion
Loading comments…