Marshall Wace interview question

Algorithmic question (LC hard) with multiple edge cases