Can someone help debug my code?

So here’s the thing… I think my logic and code works as intended but
my submission - CodeChef
passes only testcase 0…

logic used - I found min and max element in given elements, and also calculated one with max and min sqaure value. If min value is negative and max is positive then I consider the product of min and max to be correct ans, else one max square value and one least square value to be the correct ans…

So is it possible for anyone to find any test case which my submission fails to get the correct answer?
The question is SUBARRAY from September long 2022 (btw the contest ended, so i want to know why my code fails to prevent my head from exploding…)

… and, Thanks for the help

edit : Previous submission without modulus CodeChef


Why are you printing the answers modulo 10^9 + 7 ?

That didnt help tho… I added that after my submission were rejected as a desperate measure… Yes my code doesnt work even after removing them… :smiling_face_with_tear:

Share a link to that submission

I added it now, pls let me know if there are any mistakes… thanks

I guess pow(A[i], 2) is overflowing for large A[i]. Use powl() instead.

Reference: pow, powf, powl -

Or simply, you can re-write the same expression as A[i] * A[i]. This will not overflow.

1 Like

You sir are a genius… I have never heard of it, thanks for the help… There were actually two problems, one is what you mentioned, and second is my misunderstanding of input values… the given input were from -10^9 so i declared -10^9-1 to be the smallest value as global min but the ans was multiple of two values which made them reach values smaller and larger then the values I declared… Anyways, thanks for the help again…

1 Like