IBM interview question

coding question similar to leetcode.