Rain Water Harvesting(FAANG)

I solved the problem using a different approach than the solutions given in editorial.

I’m getting answers and it’s working pretty well but the code is failing in some cases because I’m not able to provide enough space for the arrays. It is given in constraint that 0 <= n <=10^6. I tried to allot that space to both array and my 2D array but segmentation error is coming which I guess is due to buffer overflow of memory.

I need help to make it pass all the cases, how can I make it work for n <= 10^6? What changes should I make?

Here’s my solution: https://ide.codingblocks.com/s/593790

u would get error allocating so much space to array… and why are u making a 2d array its anyhow increasing complexity… this ques can be done in just one d array

I know it can be done with just one d array, but I also want to know if I can solve the question somehow using my approach. System isn’t providing that much space so is there something else which can provide me that much space and help me get a solution for every possible case?

Actually I made a 2D array to provide a visual representation of the actual rainfall system constructed according to inputs. I allotted all elevated roof blocks to 0 and all the empty spaces in the system to 1 and then I used the next for loop for counting the empty storage spaces(no. of 1’s) according to the necessary conditions.

i dont think this size of array is possible… i tried searching also for the same but couldn’t get any lead… so would suggest u to go with 1d array approach only…

Sure, I tried to search too for the rectifying that size of array issue but failed, so I guess I will go with other approaches only. Thanks for clearing my doubt :smiley:

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.