TetraSoft interview question

Medium complexity