LeetCode 3550: Multi Source Flood Fill — Step-by-Step Visual Trace
Simulate multi-source BFS flood fill on a grid. Multiple colors spread simultaneously — when they collide, the maximum color wins. Approach Multi-source BFS. Start with all source cells. At each time step, expand to uncolored neighbors. Use a hash map to track the max color proposed for each cell. Apply winners and repeat. Time: O(n * m) · Space: O(n * m) Code class Solution : def colorGrid ( self , n : int , m : int , sources : list [ list [ int ]]) -> list [ list [ int ]]: ans = [[ 0 ] * m for
Comment
Sign in to join the discussion.
Loading comments…