Apple interview question

Solve coding problem with python