Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions LeetCode/medium/container_with_most_water_11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# LeetCode 11. Container With Most Water
from typing import List


class Solution:
def maxArea(self, height: List[int]) -> int:
"""
Pseudocode:
The problem is we dont know the max area where we we can store most of the water
So we can store from the start to end of the container but if the starting height of container is 1 then
max we can store height of 1 as more then that will spile the water regardless the end height
so if len is 9 and height is 1 then container can contain Area = length × width

So, what we can do it use two pointer solution to find the max area
- initialize two pointer left and right, left with value of index 0 and
right index len(arr)-1 and res which contain most largest value
- we will continue until our left and right point cross their path
- we will be moving our smallest pointer as we know smallest length contain less water
- each time we will check which one is largest previous area which stored in res
- at the end we return the res as res will be containing the largest area value we got
"""
Comment on lines +7 to +21
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix non-ASCII × in docstring and optionally tighten wording.

Ruff is flagging the × character in "Area = length × width" as ambiguous; this can break linting/CI. Consider switching to plain ASCII (e.g., length * width or length x width) and fixing a few typos for clarity.

For example:

-        so if len is 9 and height is 1 then container can contain Area = length × width
+        so if len is 9 and height is 1 then the container can contain
+        area = length * height

You could also rename len(arr) in the comments to len(height) to match the actual parameter name, but that’s purely cosmetic.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"""
Pseudocode:
The problem is we dont know the max area where we we can store most of the water
So we can store from the start to end of the container but if the starting height of container is 1 then
max we can store height of 1 as more then that will spile the water regardless the end height
so if len is 9 and height is 1 then container can contain Area = length × width
So, what we can do it use two pointer solution to find the max area
- initialize two pointer left and right, left with value of index 0 and
right index len(arr)-1 and res which contain most largest value
- we will continue until our left and right point cross their path
- we will be moving our smallest pointer as we know smallest length contain less water
- each time we will check which one is largest previous area which stored in res
- at the end we return the res as res will be containing the largest area value we got
"""
"""
Pseudocode:
The problem is we dont know the max area where we we can store most of the water
So we can store from the start to end of the container but if the starting height of container is 1 then
max we can store height of 1 as more then that will spile the water regardless the end height
so if len is 9 and height is 1 then the container can contain
area = length * height
So, what we can do it use two pointer solution to find the max area
- initialize two pointer left and right, left with value of index 0 and
right index len(arr)-1 and res which contain most largest value
- we will continue until our left and right point cross their path
- we will be moving our smallest pointer as we know smallest length contain less water
- each time we will check which one is largest previous area which stored in res
- at the end we return the res as res will be containing the largest area value we got
"""
🧰 Tools
🪛 Ruff (0.14.7)

12-12: Docstring contains ambiguous × (MULTIPLICATION SIGN). Did you mean x (LATIN SMALL LETTER X)?

(RUF002)

🤖 Prompt for AI Agents
In LeetCode/medium/container_with_most_water_11.py around lines 7 to 21, the
docstring uses a non-ASCII multiplication sign "×" and has a few
wording/identifier mismatches that trip linters; replace "Area = length × width"
with an ASCII form like "Area = length * width" (or "length x width"), correct
typos (e.g., "dont" → "don't", "spile" → "spill"), and change references from
len(arr) to len(height) to match the function parameter; keep the two-pointer
explanation the same but tighten wording for clarity.

res = 0
left, right = 0, len(height) - 1
while left < right:
area = (right - left) * min(height[left], height[right])
res = max(res, area)

if height[left] < height[right]:
left += 1
else:
right -= 1
return res
40 changes: 15 additions & 25 deletions tests/test_leetcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,28 +469,18 @@ def test_min_number_operations(target, expected):
assert minOperations(target) == expected


# @pytest.mark.performance
# def test_bank_performance():
# from LeetCode.medium.simple_bank_system_2043 import Bank

# n = 100_000
# bank = Bank([1000] * n) # 100k accounts, each with balance 1000
# operations = 200_000

# start = time.perf_counter()

# for _ in range(operations):
# op_type = random.choice(["deposit", "withdraw", "transfer"])
# a1 = random.randint(1, n)
# money = random.randint(1, 100)

# if op_type == "deposit":
# bank.deposit(a1, money)
# elif op_type == "withdraw":
# bank.withdraw(a1, money)
# else: # transfer
# a2 = random.randint(1, n)
# bank.transfer(a1, a2, money)

# end = time.perf_counter()
# print(f"\nTotal time for {operations} ops on {n} accounts: {end - start:.3f}s")
# LeetCode 11: Container with most water
@pytest.mark.parametrize(
"height, expected",
[
([1, 8, 6, 2, 5, 4, 8, 3, 7], 49),
([1, 1], 1),
([4, 3, 2, 1, 4], 16),
([1, 2, 1], 2),
],
)
def test_max_area(height, expected):
from LeetCode.medium.container_with_most_water_11 import Solution

solution = Solution()
assert solution.maxArea(height) == expected
Loading