IBM interview question

leetcode easy to medium problem solving.