Your question is Nearest Edge Distance Map. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Given a binary matrix image of size m x n where 0 represents background and 1 represents foreground, return an m x n matrix dist where dist[r][c] is the minimum 4-directional distance from cell (r, c) to any background cell. Distances are measured using up, down, left, and right moves. If a cell is already background, its distance is 0.
def nearest_edge_distance(image):