Metaswitch interview question

How can you make your suggested solution to this exercise more efficient?