IBM interview question

Easy-Medium Leetcode, not too hard