IBM interview question

Two leetcode mediums, pretty reasonable