Rain Water Harvesting

following error occured during running code. i didn’t get it.

program: malloc.c:2394: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)’ failed.

Rajesh, pls send your code by saving on ide so that I could check it.

#include
using namespace std;

int rainWaterHarvesting(int *arr, int size)
{
int *left = new int[size];
int *right = new int[size];

// left most array
int temp = arr[0];

for (int i = 0; i < size; ++i)
{
	if (arr[i] > temp )
	{
		temp = arr[i];
		left[i] = temp;
	}
	else
		left[i] = temp;
	
}


// right most array
int temp1 = arr[size - 1];

for (int i = size - 1; i >= 0; --i)
{
	if (arr[i] > temp1)
	{
		temp1 = arr[i];
		right[i] = temp1;
	}
	else
		right[i] = temp1;
	
}

// Water array
int Water = 0;

for (int i = 0; i < size; ++i)
{
	Water += min(left[i],right[i]) - arr[i];
}

return Water;

}

int main(int argc, char const *argv[])
{
int N;
cin >> N;

int *arr = new int[N];

for(int i = 0; i < N; i++)
{
	cin >> arr[i];
}

int ans = rainWaterHarvesting(arr,N);
cout<< ans << endl;
return 0;

}

Rajesh, pls try to submit your code, it is working perfectly fine, working on all test cases,

This is the ide for the code,

but what’s the problem then

now it is submitted. thank u