Mantaro Brands Interview Question

how can you optimize query?