Forvis Mazars Group Interview Question

How to avoid nested loops?