Pregunta de entrevista de MAQ Software

Interviewer asked me to write a code in python which was of medium difficulty level.