Facebook | Phone
Anonymous User
3663

I had a FB phone screen yesterday that didn't go particularly well. The question seemed like a variant of merge intervals, I believe? It was essentially:

Given several schedules, find a time slot when all people are free for a given amount of time.

e.g.
User 1: [8:00 - 10:00, 11:00 - 12:00, ...]
User 2: [9:00 - 10:00, 12:00 - 1:00, ...]
User 3: [11:00 - 12:00, ...]
etc.

I mentioned several different approaches to the interviewer that I think would have worked, but he seemed to push me toward an approach where I would have a separate pointer to each list and then at each iteration I would output one merged interval corresponding to the earliest possible merged interval; i.e. combining User 1 8:00 - 10:00 and User 2 9:00 - 10:00 and leaving the pointer to User 3 where it was.

Maybe I misunderstood him somewhere along the way, but this doesn't feel like an optimal solution? In the worst case, I could construct all non-overlapping intervals so that I'd have to do U * N comparisons where U is the number of users and N is the total number of intervals, no?

Curious if this is a question on Leetcode that I haven't seen and what the optimal approach should be.

Comments (10)