HAY interview question

Leetcode medium followed by discussions from the cv