Pregunta de entrevista de IBM

Leetcode style question from easy to mid range.