Problem with the return type [Memory Limit Exceeding]

Is there a problem with the expected return type. The return type mentions a vector but I guess it is causing the memory limit to exceed. Even the editorial solution fails. Is anyone else facing the same issue? Can someone explain why this might be happening?

Click here to start solving coding interview questions