ByteDance interview question

A coding question on floodfill, BFS.