dsa2 min read
Pacific Atlantic Water Flow — Reverse BFS from Both Oceans
Find cells that can flow to both oceans by doing reverse BFS from each ocean's borders and finding the intersection.
Read →
1575 articles
Find cells that can flow to both oceans by doing reverse BFS from each ocean's borders and finding the intersection.
Maximize score jumping through an array with window k by combining DP with a monotonic decreasing deque.
Find the shortest subarray with sum >= k using a monotonic deque on prefix sums for O(n) time.
Fill each empty room with its distance to nearest gate using simultaneous multi-source BFS from all gates.
Implement an iterator for a nested list using a stack that lazily expands nested lists as elements are consumed.