Sizes of connected regions in a binary image, in scan order

0
Remix

A binary image is an m x n grid of 0s and 1s. Foreground pixels (1s) that touch up, down, left or right belong to the same region; diagonal neighbours do not. Return the size of every region, listed in the order you first meet a pixel of that region when scanning the image row by row, left to right. Discuss BFS versus DFS, recursion depth on large images, and the time and space cost.

MicrosoftCodingLast asked Sep 2026
No answer yet. Write the first one; the best answer gets endorsed.