2 TCs giving TLE in Matrix Query - 1 Problem

my sol : https://ide.codingblocks.com/s/253573

i am not able to understand why the code is giving TLE on 2nd and 3rd TCs.

The code looks fine to me both in terms of space and time complexities.

Pls tell me where my code can be optimised or whether their is some problem with the TCs

@saarthakseth,
Don’t return matrix multiplication, do it in place using pass by reference.

tried it but still giving tle

my sol after change : https://ide.codingblocks.com/s/253599

btw how will it effect time complexity ?? according to me it shouldn’t have any effet !

@saarthakseth,
It will not affect time complexity, but time constraints are tight so minor optimisations will help.
Also use global arrays rather than vectors.

it’s still giving TLE ! can u pls tell where my code can be optimized as i’ve used the same approach as told in the hint video and the complextity of my code looks fine 2 me

@saarthakseth,
As I said, complexity of your code is fine, but minor optimisations help when time constraints are tight.
You calculate complexity by ignoring constants and less significant terms, but sometimes, they turn out to be of significant when runtime is concerned.
Please link you updates code with the optimisations I suggested.
Anyways, I have seen your code, your logic as well as implementation are correct in general, you can skip this problem for now if you want to.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.