Zaber Technologies interview question

Similar to leet code problems.