Finding point in 2D array furthest away from specific elements

I’d like to find out how to make a script to find the furthest point away from a specific number in a 2D array. In this case, that number is 1. I’d like to have a script that can turn this:
into this:

That might be harder than it seems.

Here is what I would try.

Make a new table. Insert coordinates of every empty position (0) as a vector2 in a candidate array.

Make another new table and insert the coordinate of every position you want to avoid (1) as a vector2.

Make variables for bestCoordinate and bestMagnitude.

First, set bestMagnitude=0 to begin with.

Then work your way through the candidate array to find the coordinate that is best. Bigger magnitudes are better:

Make a for loop that goes through the candidateCoordinate array. Inside, initialize a Boolean isBetter=true and make another loop that goes through the avoidCoordinates array. Inside the inner loop, check if the magnitude is smaller than bestMagnitude, then set isBetter=false and use break to get out of the inner loop. After the inner loop, if isBetter then set the bestMagnitude and bestCoordinate to the value that you found.

Finally, set the array value, using the best coordinates that you found.

It may not work well for large arrays, in terms of performed.

And there may be a bug in my description, I cannot make promises about it. But if you code something and have problems, try to post your code for us.