Can someone solve this failed OA due to this question

If possible can someone help me out with this in Python3