Most time-efficient method for resolving the following problem : learnpython

I can’t find the answer to this type of problem anywhere and most of my solutions seem to be very time-consuming. I’m wondering if this can be…