Nagarro Interview Question

Optimization of the code.