Domanda di colloquio di Morningstar

optimize a certain part of the code from the assignment