Expedia SSE screen — merge intervals + non-overlapping trades; passed
After the initial call with a recruiter, I got scheduled with an engineer.
I had 2 problems. First is merging intervals. Given intervals of [start_time, end_time], I need to merge overlapping intervals and return a new array of merged intervals. If there are no overlapping intervals, then I need to return an array of one interval which covers all given intervals. I passed this quickly and answered time complexity.
Second one was harder. I was given an array of stock trading logs: [buy_time, sell_time, profit]. Given the logs, I can choose trades which don't overlap (sell_time and buy_time can be equal). Choose non-overlapping trades that sum up to maximum profit.
I found a slightly better than brute-force algorithm. But because of my binary search method's bug, I couldn't pass one of 3 test cases. Once 60 minutes was done, the engineer asked what the time complexity of my solution was and I answered correctly.
Thankfully I just got an invitation to the next round.
The loop · 1 round
Merge intervals; maximum total profit from non-overlapping stock trades (weighted interval scheduling)