Rain water harvesting 1

in the following code if we declare a[1000000], l[1000000], r[1000000] arrays globally that is just above main then only it gives correct answer.

if we declare a[1000000], l[1000000], r[1000000] as local arrays that is inside int main function then it shows error and does not compute the answer.

does declaring array globally or locally is different??

please look into it. this is the code -

Yes if you declare an array locally, the maximum size that integer array can have is of order 10^5.
But if you declare its globally, the maximum allowed size increases to order 10^7.
So whenever you have to declare an array this large, you should declare it globally

1 Like

@pratyush63 okay thank u sir i got it.