Programming Question : Leetcode 11
Approach to solve leetcode 11 — Container With Most Water
- In this question, we are asked to calculate area between two bars, that will be calculated as (distance between bars)*(height of smaller bar).
- we will start two pointers one from start and other from end , and keep calculating area between the bars. Now, as we need smaller bars(because water can be filled up to the height of smaller bar) so if right side bar is smaller , we will decrement its pointer and if left side bar is smaller we will decrement its pointer until start is less than or equal to end.
- at the end we will return maximum area .
Code:
