Citi interview question

Easy and medium leetcode question