Bloomberg Interview Question

2 algorithm medium problem. you could try to practice in leetcode