The text description doesn’t match the code:
- the text describes outside-in approach where we enqueue all 'W’s at the border and explore inner 'W’s that are reachable from the border using BFS
- the actual code is inside-out approach where for each ‘W’ we try to find a path to the border, marking all elements of unsuccessful path as 'B’s
In my opinion, the outside-in approach is easier to code.