-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Problem 1: visibility to the ocean to the right
# height of the buildings
h = {5,4,3,4,2}
# indexes where we see the ocean to the right
v = {0,3,4}
Solution 1: Iterative
- start at the right
- maintain a max height var
- initially set it to 0
- iterate position 4, max = h[4] = 2, push to right pos 4 to v where v = {4}
- iterate position 3, max = h[3] = 3, push to right pos 3 to v where v = {3,4}
- iterate position 2, max > pos, no op
- iterate position 1, max = pos, no op
- iterate position 0, max < pos = 5, push to right pos 0 to v where v = {0,3,4}
Recursive
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels