Question: in c++ Write a function int howmuchwater(unsigned int a[], int n) where a[] is a 1D array where a[i] reports the number of blocks stacked

in c++

Write a function int howmuchwater(unsigned int a[], int n)

where a[] is a 1D array where a[i] reports the number of blocks stacked atop square i n is the number of elements in a[] and returns the cubic feet of trapped water from blocks described in a[] if n>0 and a[] is non-null, otherwise returns -1.

Examples:

a)

 b b b b b b b b b ++++++++++ 7

b)

 b b bb b b bb bbbbbbb +++++++++++++ 6

c)

+++ 0

d)

 b +++ 0

e) -1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!