Grand Temple Problem

I tried implementing the code,and the answer of the given test case comes out to be right, However, on submitting I’m getting the wrong answer. Please help.

LINK : https://ide.codingblocks.com/s/340791

hello @gptradhika1208 you have made 2-3 mistakes like you are not taling n as input . you have just declared it .
moreover see the test cases .
as the test cases are larger i guess after taking input of n also you would not be able to pass all the test cases because the elements of the array can be of order of 10^9 that’s why .
here for your reference i am attaching the correct code


if you feel your doubt is clear pleasemark it as resolved .
Happy Learning !!

I forgot to take the input of n, but the rest of the logic was correct,right? Also, why do we run the loop only till < n-1. I mean don’t we have to calculate dx and dy for the last input?

@gptradhika1208 we are ruuning our loop till n-1 because the when we are finding max between two there we are doing this max(dx,x[i+1]-x[i]-1) in this condition if you have seen clearly we are subtracting ith from i+1 so of we run our loop till n then do you think that there will be any valid element present at n th index but any garbage value.
if you feel your doubt is cleared please mark it as resolved .
Happy Learning !!

Okay,got it. Thanks!