Beyondsoft Group interview question

leetcode easy and medium question