WADIC interview question

solve the given programming challenge