FareHarbor interview question

Algorithms: leetcode medium problem, nothing unusual but trickier than the previous one