Rain water Harvesting - faang

I tried to solve the question by using the second better approach used in editorial but when I’m trying to run it, it’s giving an error - Segmentation fault. I checked my code twice and didn’t found a issue, what could be the problem?

Here’s the code: https://ide.codingblocks.com/s/594306

just declare the arrays globally… it will work fine… due to large size it gives error if defined in function and main… i have corrected ur code https://ide.codingblocks.com/s/594308

Sure, I understood. Why is it happening though? Why does declaring the arrays globally solve the problem?

when the array is declared of big size then the stack memory gets full and leads into the stack overflow error, and therefore, a segmentation fault error is encountered. Therefore, for declaring the array of larger size, it is good practice to declare it globally…

Understood it now! Thank you!

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.

I tried to run the code and it’s working but I faced an issue while doing it. If I am trying to use the names left and right for arrays, it is saying that reference to left and right is ambiguous if I use some other name like left1 like you used it’s giving the right answer. Not able to understand why it’s happening, does left and right comes under keywords or are they reserved already for some other operations?

maybe left and right are being considered as some keywords while declaring globally…

Actually I tried to search it and just came up on a stack overflow discussion. According to it left and right is declared in std library and that’s the reason we can’t use it. So yup I’m clear with the doubt now.

ok … cool… hope ur doubt is cleared now…

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.