Pregunta de entrevista de Affirm

Scenario based question and solved using python