Skip to content
Open
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
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@ You are now asssisting with Market Making Oleos. Due to some changes to legislat
Please include the following when you are writing your PR:
General things:
1. What is the purpose of this PR?
finished step 3

2. What changes did you make? Why?
Changed the brute force approach into using two pointers.

3. What bugs did you find while testing?
n/a. Poetry wouldn't work so I just made sure that my code works :))

This PR Specific:
1. What was the bug you found?
It is too slow.
2. How did you address it?
I used a two pointer approach. It would at most take O(n) time.
3. What did you struggle with?
//
4. Is there anything you would change about this step?
5. What was the code given to you by the tests?
// Perhaps don't use a LC problem tho:)
5. What was the code given to you by the tests?
Looked at it afterwards. its a binary string?
1 change: 1 addition & 0 deletions src/baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ def max_area(height):
max_area = max(max_area, current_area)

return max_area

22 changes: 12 additions & 10 deletions src/improved.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
def max_area(height):
max_area = 0
n = len(height)
res = 0
l, r = 0, len(height) - 1

for i in range(n):
for j in range(i + 1, n):
h1 = height[i]
h2 = height[j]
width = j - i
current_area = min(h1, h2) * width
max_area = max(max_area, current_area)
while l < r:
res = max(res, min(height[l], height[r]) * (r - l))

return max_area
if height[l] < height[r]:
l += 1
else:
r -= 1

return res

#this is LC 11, no?