Citadel interview question

Solve problem in python please