From 148e2c0b37e6364b3a49e942cebc28e18e367de9 Mon Sep 17 00:00:00 2001 From: Peter L <85031672+pl712@users.noreply.github.com> Date: Tue, 17 Oct 2023 23:24:00 -0500 Subject: [PATCH 1/3] Update baseline.py --- src/baseline.py | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/baseline.py b/src/baseline.py index 722c894..4392a22 100644 --- a/src/baseline.py +++ b/src/baseline.py @@ -1,13 +1,28 @@ def max_area(height): - max_area = 0 - n = len(height) - - 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) - - return max_area + # max_area = 0 + # n = len(height) + + # 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) + + # return max_area + + res = 0 + l, r = 0, len(height) - 1 + + while l < r: + res = max(res, min(height[l], height[r]) * (r - l)) + + if height[l] < height[r]: + l += 1 + else: + r -= 1 + + return res + + #this is LC 11, no? \ No newline at end of file From b441a61ef7dedd0c051814308dc1401f179e9480 Mon Sep 17 00:00:00 2001 From: Peter L <85031672+pl712@users.noreply.github.com> Date: Tue, 17 Oct 2023 23:26:56 -0500 Subject: [PATCH 2/3] finish --- src/baseline.py | 34 ++++++++++------------------------ src/improved.py | 22 ++++++++++++---------- 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/src/baseline.py b/src/baseline.py index 4392a22..ee9a62b 100644 --- a/src/baseline.py +++ b/src/baseline.py @@ -1,28 +1,14 @@ def max_area(height): - # max_area = 0 - # n = len(height) + max_area = 0 + n = len(height) - # 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) + 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) - # return max_area + return max_area - res = 0 - l, r = 0, len(height) - 1 - - while l < r: - res = max(res, min(height[l], height[r]) * (r - l)) - - if height[l] < height[r]: - l += 1 - else: - r -= 1 - - return res - - #this is LC 11, no? \ No newline at end of file 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? From 5b6fcf61b195e04a0275217a12416ea5398ec8d9 Mon Sep 17 00:00:00 2001 From: Peter L <85031672+pl712@users.noreply.github.com> Date: Tue, 17 Oct 2023 23:30:06 -0500 Subject: [PATCH 3/3] Update README.md --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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