Skip to content

Commit 32b871f

Browse files
author
Joseph Luce
authored
Update 778_swim_in_rising_water.md
1 parent 8cf1077 commit 32b871f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

leetcode/hard/778_swim_in_rising_water.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# 778. Swim in Rising Water
22

33
## Heap Solution
4-
- Runtime: O(N * Nlog(N))
4+
- Runtime: O(T * Nlog(N))
55
- Space: O(N)
66
- N = Number of elements in grid
7+
- T = Time
78

89
You may have thought to use BFS for this question, but the problem is the fact that we cannot swim to an element in the grid until the water is at its level.
910
So we have a second issue to figure out which elements are up to the water's level.
@@ -16,7 +17,7 @@ The logic goes as follows:
1617
1. As long as there are elements in the heap.
1718
2. Increment time + 1.
1819
2. Continue popping off the min heap until the top of the heap is > time.
19-
2. For each popped off element, if the element popped off is the last element, return current time.
20+
2. For each popped off element, if the element popped off is the bottom-right element of the grid, return current time.
2021
2. Add all neighbors of the popped elements into the min heap. Keep a visited set to not add duplicate elements into the heap.
2122
5. Repeat.
2223

0 commit comments

Comments
 (0)