znt-Richter interview question

Solve the programming problem and explaining on it