Hi Greg, graph problems scared me at first, but after watching your videos and how wonderfully you break everything down into simple code, I'm getting more confident with them! Thanks a lot.
Here is my solution that I come up with after hearing your thought process. It might be simple to understand : from collections import deque class Solution: def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]: rows , cols = len(heights), len(heights[0]) visited_p = [[0 for _ in range(cols)] for _ in range(rows)] visited_a = [[0 for _ in range(cols)] for _ in range(rows)] row_col_list = [(1,0),(-1,0),(0,1),(0, -1)] set_p = set() set_a = set() que_p = deque() que_a = deque() for r in range(rows): for c in range(cols): if r == 0 or c == 0: set_p.add((r,c)) que_p.append((r, c, heights[r][c])) visited_p[r][c] = -1 if r == rows - 1 or c == cols -1: set_a.add((r,c)) que_a.append((r, c, heights[r][c])) visited_a[r][c] = -1 while que_p: rqp, cqp, htqp = que_p.popleft() for rl, cl in row_col_list: rn = rqp + rl cn = cqp + cl if 0
i_o and j_o are offsets.. so for [0,1], r ,c = i+0,j+1, so j is incremented, so it is square right to i,j. We go through the list of all 4 neighboring squares to check if water can flow from them to us
Master Data Structures & Algorithms For FREE at AlgoMap.io!
Hi Greg, graph problems scared me at first, but after watching your videos and how wonderfully you break everything down into simple code, I'm getting more confident with them! Thanks a lot.
I compared this solution to other channels' solution and I feel yours is the most easiest to read and understand. Thanks 😇
Broke down a complex problem beautifully
Here is my solution that I come up with after hearing your thought process. It might be simple to understand : from collections import deque
class Solution:
def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]:
rows , cols = len(heights), len(heights[0])
visited_p = [[0 for _ in range(cols)] for _ in range(rows)]
visited_a = [[0 for _ in range(cols)] for _ in range(rows)]
row_col_list = [(1,0),(-1,0),(0,1),(0, -1)]
set_p = set()
set_a = set()
que_p = deque()
que_a = deque()
for r in range(rows):
for c in range(cols):
if r == 0 or c == 0:
set_p.add((r,c))
que_p.append((r, c, heights[r][c]))
visited_p[r][c] = -1
if r == rows - 1 or c == cols -1:
set_a.add((r,c))
que_a.append((r, c, heights[r][c]))
visited_a[r][c] = -1
while que_p:
rqp, cqp, htqp = que_p.popleft()
for rl, cl in row_col_list:
rn = rqp + rl
cn = cqp + cl
if 0
I still struggle on how you were able to come up with the solutions to most of these! @_@
This make me feel like a stupid
Hi Greg ! Can I ask for your discord community server ? I saw it somewhere but now Im unable to find it
Right here! discord.com/invite/g4ZnYzTB
Great work.... Can you make videos for DSA concepts too!
Thanks! Yeah after this leetcode playlist is done I'll be doing a playlist on the generic theory
@@GregHogg fast as you can....🤝🏻
lol this seems to be the hardest solution in your series (and i have finished even the dp ones in yours)
thanks
Your discord server link is invalid
Bro what is r, c = i+i_o, j+j_o, can you explain bro i don't understand 😢
i_o and j_o are offsets.. so for [0,1], r ,c = i+0,j+1, so j is incremented, so it is square right to i,j. We go through the list of all 4 neighboring squares to check if water can flow from them to us