IBM interview question

basic leetcode question you can see in easy/medium