Old question: merge segments.
// Sample Input:
// [
// [(1,1),(2,2),(4,4)], // lane segment (x, y)
// [(2,1),(4,2)],
// [(3,3),(6,6)],
// [(7,7),(8,8)]
// ]
// Sample Output:
// [
// [(1,1),(2,2),(3,3),(4,4),(6,6)], // lane segment
// [(7,7),(8,8)],
// [(2,1),(4,2)]
// ]
You also have to think about how to handle slope 0.
Solution: a math problem plus merge intervals.
Now let me complain about this company's interview. The phone screen was 45 minutes in total: 5 min intro + 5 min Q&A, so that leaves 35 min for the problem, and you still have to communicate the whole time. 🙄 Even if I had seen it before and practiced in Java, I'd be damned if I could finish it. While reviewing I knew I would never be able to solve this one if I got it, so I just glanced at it and didn't study it. Sure enough, before I had written anything I had already spent ages discussing with the interviewer how to compute the slope.
I don't understand why this company asks this problem. With this timeline, writing half of it is about the same as writing the other half, never mind the corner cases. From what I see on the forum, a lot of people feel the workload is heavy, the company's expected payoff isn't that high, and in the self-driving space it counts as one of the established names. I don't get why they interview with such a hard coding problem. If the recruiter had told me this was the problem, I'd have suggested they cancel my interview.
Discussion
Loading comments…