Cisco interview question

how to improve time complexity of program