Skip to content

add : trapped water program under dynamic programming #10027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Oct 7, 2023
Merged
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
441cebc
to add the trapped water program
kosuri-indu Oct 7, 2023
7ebd539
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 7, 2023
aad0efb
to make changes for error : B006
kosuri-indu Oct 7, 2023
04c87a7
Merge branch 'add/trapped_water_problem' of https://github.com/kosuri…
kosuri-indu Oct 7, 2023
95ff91c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 7, 2023
b18f44a
to make changes for error : B006
kosuri-indu Oct 7, 2023
d514b2e
to make changes for error : B006
kosuri-indu Oct 7, 2023
ddf7b99
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 7, 2023
6962866
to make changes in doctest
kosuri-indu Oct 7, 2023
acaf9a7
Merge branch 'add/trapped_water_problem' of https://github.com/kosuri…
kosuri-indu Oct 7, 2023
dadd1a9
to make changes in doctest
kosuri-indu Oct 7, 2023
42021c4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 7, 2023
d61cbea
Update dynamic_programming/trapped_water.py
kosuri-indu Oct 7, 2023
3f9951d
Update dynamic_programming/trapped_water.py
kosuri-indu Oct 7, 2023
03984af
to make changes in parameters
kosuri-indu Oct 7, 2023
3634905
Merge branch 'add/trapped_water_problem' of https://github.com/kosuri…
kosuri-indu Oct 7, 2023
eaa775e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 7, 2023
bf94d38
to make changes in parameters
kosuri-indu Oct 7, 2023
d980935
to make changes in parameters
kosuri-indu Oct 7, 2023
1ca6701
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 7, 2023
10609bc
Update dynamic_programming/trapped_water.py
kosuri-indu Oct 7, 2023
a0854dd
to make changes in parameters
kosuri-indu Oct 7, 2023
7f9f1f1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 7, 2023
d684771
for negative heights
kosuri-indu Oct 7, 2023
9230589
Update dynamic_programming/trapped_water.py
kosuri-indu Oct 7, 2023
20b78d5
to remove falsy
kosuri-indu Oct 7, 2023
473a87d
Merge branch 'add/trapped_water_problem' of https://github.com/kosuri…
kosuri-indu Oct 7, 2023
f17ff76
Final edits
cclauss Oct 7, 2023
1bb35ee
tuple[int, ...]
cclauss Oct 7, 2023
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
7 changes: 3 additions & 4 deletions dynamic_programming/trapped_water.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
on both sides minus height of bar at current position.
"""


def trapped_rainwater(height: list[int]) -> int:
def trapped_rainwater(height : list[int] = None) -> int:
"""
The trapped_rainwater function calculates the total amount of rainwater
that can be trapped given an array of bar heights.
Expand All @@ -32,8 +31,8 @@ def trapped_rainwater(height: list[int]) -> int:

left_max = [0] * length
left_max[0] = height[0]
for i in range(1, length):
left_max[i] = max(height, left_max[i - 1])
for i in range(1,length):
left_max[i] = max(height[i], left_max[i - 1])

right_max = [0] * length
right_max[length - 1] = height[length - 1]
Expand Down