i can't understand how to reduce time of my code

sir my question ID 18838931 is getting time limit exceeded problem.please reply sir,i’m very nervous and this is my 1st submission.

Did you try to understand from editorial?

What is the question (problem which you are solving)?

Okay i saw your solution. You see you don’t have to loop over minX and maxX checking the final value for only 1 and 0 would be sufficient ,because you see if you are checking for number minX <= z <= maxX say, the result modulo 2 would be same as x=0 if z is even or x=1 if z is odd. now you need to check how many even and odd numbers are between minX and maxX which can be done efficiently by doing (maxX-minX)/2 + 1 for even numbers similarly you can calculate for odd numbers. and calculate the ans this would give complexity O(t* n) which is efficient

@jogi_9: Please give meaningful titles like “Reducing Time Complexity of My solution of problem SPAMCLASS”.

Also, instead of giving your solution id, it’s better to give the link itself. Even better to paste it here itself unless the code contains too many lines.

1 Like

Yaa really, i agree

@ssp547,@vikram_91 what is weird to me is that my solution is of complexity O(t*n), yet the verdict is tle

…Here is my code:


… here is the question:

Can anyone explain how to reduce time complexity further now.