Given **N** non-negative integers where each represents a point at coordinate . **N **vertical lines are drawn such that the two endpoints of line** i **is at and . Find two lines, which together with x-axis forms a container, such that the container contains the most water.

**Input: **

The first line of input contains an integer **T** denoting the number of test cases. Each test case contains an integer **N** followed by **N** space separated integers.

**Output:**

For each test case, the output is the integer denoting the maximum area of water that can be contained ( maximum area instead of maximum volume as working with 2D)

**Constraints:**

1 <= T <= 100

2 <= N <= 50

1 <= A[] <= 100

**Example:
Input:**

2

4

1 5 4 3

5

3 1 2 4 5

6

12

**Explanation:**

1. 5 and 3 are distance 2 apart. So the size of the base = 2. Height of container = min(5, 3) = 3. So total area = 3 * 2 = 6.

2. 5 and 3 are distance 4 apart. So the size of the base = 4. Height of container = min(5, 3) = 3. So total area = 4 * 3 = 12.

Author: Vanshika_pec

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

saiujwal13083 | 347 |

isiddhisingh | 252 |

Abhishek_Jadhav | 243 |

_uncle_sam_ | 221 |

c_ocoooo | 217 |

saiujwal13083 | 610 |

SumitSingh27 | 466 |

c_ocoooo | 456 |

rathiarpit29 | 379 |

NaveenKumarNakka | 370 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4931 |

Quandray | 4598 |

Login to report an issue on this page.