diff --git a/README.md b/README.md index f7eb8ad..52293ad 100644 --- a/README.md +++ b/README.md @@ -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? \ No newline at end of file +// 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? \ No newline at end of file diff --git a/src/baseline.py b/src/baseline.py index 722c894..ee9a62b 100644 --- a/src/baseline.py +++ b/src/baseline.py @@ -11,3 +11,4 @@ def max_area(height): max_area = max(max_area, current_area) return max_area + diff --git a/src/improved.py b/src/improved.py index 722c894..e7a0d48 100644 --- a/src/improved.py +++ b/src/improved.py @@ -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?