int maxProduct(int *arr, int n){
int S = 0, S1 = 0, max = INT_MIN;
for(int i = 0; i < n; i++)
S += arr[i];
for(int i = 0; i < n-1; i ++){
S1 += arr[i];
int product = S1*(S-S1);
if(product > max)
max = product;
}
return max;
}

I realized that interviewer actually made a mistake. if a maze is MxN and only one cell is empty, in this case it is impossible to get the count of obstacles by traversing. Either he forgot to add some condition or he gave a wrong question.