About the logic in the program

Can it be solved using the technique used in harvesting rainwater problem or can that problem be solved using stack?