Aera Technology interview question

Python code