Kinexcs interview question

Question directly copied from leetcode