src.most_water_container¶
Classes
|
- class src.most_water_container.Solution[source][source]¶
- maxArea(height: list[int]) int [source]¶
Thought process¶
Once again basic two point setup so
l, r = 0, len(height) - 1
andwhile l < r
The area is the base length times $ r - l $ the height of the smaller wall \(\text{min}(h[l], h[r])\)
We can move the pointer with the smaller wall since moving the pointer with the larger wall will only decrease the area
We repeat this process until the pointers cross over
Notes¶
time complexity: \(O(n)\) just a single loop
space complexity: \(O(1)\)
- maxAreaBruteForce(height: list[int]) int [source]¶
Thought process¶
We can brute force this by checking all possible areas
We can do this by having two loops and checking all possible combinations of areas
We can then return the maximum area
Notes¶
time complexity: \(O(n^2)\) ⚠️ does not pass time limit
space complexity: \(O(1)\)