FiTec interview question

Algorithms problem