inside the while loop of MarkRegionIfSurrounded(…), once you check if a point is W and border, you are not doing BFS of the remaining nodes adjacent to it
Consider this example where you code wont work
B B B B
W W B B
B B B B
B B B B
in this above case, when you call the API for (1,0), it will figure its a boundary (keep it as is) and leave the function without processing the remaining nodes. So, the next time, when it comes for 1,1 , it will mark it as B even though a route exists to the boundary from 1,0 (As the if check fails and for loop inside else will not add 1,0 to the queue given its already visited)
In my opinion, one correct way is to have a bool that tells if we discovered a W close to boundary anytime during BFS. However, we keep continuing BFS until we exhaust all adjacent W and mark them visited (and eventually leave them as is)
In the event we don’t find a boundary, for all the Ws in the queue, we just turn them B. Makes sense?
Let me know if I am missing something