Problem Statement
A swimming pool of a very complicated shape, but of uniform depth is filled to a certain height one day by the rain. You have determined the rates at which water entered the swimming pool in cubic meters per second for a number of time periods. With this information you are able to calculate the total volume of water that entered the pool, and given the height to which the pool was filled, you can now determine the cross-sectional area of the pool. For example, if a total volume of 100 cubic meters of water flowed into the pool and filled it up to a height of 10 meters, then you would know that the cross-sectional area of the pool was 10 square meters.
You must write a method that takes as input a
Definition
- Class:
- SwimmingPool
- Method:
- area
- Parameters:
- int[], int[], int
- Returns:
- int
- Method signature:
- int area(int[] rates, int[] durations, int height)
- (be sure your method is public)
Constraints
- rates will contain between 1 and 50 elements, inclusive.
- rates and durations will contain the same number of elements.
- Each element of rates will be between 1 and 100, inclusive.
- Each element of durations will be between 1 and 100, inclusive.
- height will be between 1 and 100, inclusive.
Examples
{1,2,3,4}
{1,2,3,4}
10
Returns: 3
{1,2,3,4,5}
{5,4,3,2,1}
1
Returns: 35
the total amount of rain to fall is 35 cubic meters. Thus the cross-sectional area is 3.5.
{1,2,3,4,5}
{5,4,3,2,1}
10
Returns: 3
The total amount of rain to fall is 35 cubic meters. Thus the cross-sectional area is 3.5.
{5,4,3,2,1}
{1,2,3,4,5}
100
Returns: 0
{100}
{1}
100
Returns: 1
{100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}
{100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}
100
Returns: 5000
{100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}
{100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}
97
Returns: 5154
{100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}
{100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}
1
Returns: 500000
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50}
{50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1}
45
Returns: 491
{5,8,4,3}
{4,2,3,9}
64
Returns: 1
{3,1,4,1,5,9,2,7}
{2,7,7,2,7,7,2,3}
54
Returns: 3
{56,1,2,6,4,9}
{5,65,32,48,59,2}
5
Returns: 190
{3}
{1}
4
Returns: 0
{5,5,5,5,5}
{6,7,8,9,10}
2
Returns: 100
{1,2,3,4,5}
{5,4,3,2,1}
10
Returns: 3
{25,25}
{10,15}
7
Returns: 89
{5,8,4,3}
{4,3,2,9}
64
Returns: 1
{ 1, 2, 3, 4 }
{ 1, 2, 3, 4 }
10
Returns: 3
{ 1, 2, 3, 4, 5 }
{ 5, 4, 3, 2, 1 }
10
Returns: 3
{ 5, 5, 5, 5, 5 }
{ 6, 7, 8, 9, 10 }
2
Returns: 100
{ 25, 25 }
{ 10, 15 }
7
Returns: 89
{ 3 }
{ 1 }
4
Returns: 0
{ 1, 2, 3, 4, 5 }
{ 5, 4, 3, 2, 1 }
1
Returns: 35