Neeva interview question

a Leetcode easy to medium problem