Wells Fargo interview question

Try to edit the given code for better performance