Infosys Interview Question

How to avoid loop inside loop