Marshall Wace Interview Question

Algorithmic question (LC hard) with multiple edge cases