Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
For each square, know how many ones are up, left, down, and right of this square. You can find it in O(N^2) using dynamic programming.
Now for each square ( O(N^3) ), we can evaluate whether that square is 1-bordered in O(1).