Solved LeetCode program · 850 of 1,000
#1139 · Largest 1-Bordered Square
Original English source
The grid is a list of 1, 1, 1, 1, 0, 1, 1, 1, and 1. The size is 3. The best is 0.
For every side from 1 to size.
For every top from 0 to size minus side.
For every left from 0 to size minus side.
The bottom is top plus side minus 1. The right is left plus side minus 1. The good is 1.
For every step from 0 to side minus 1.
The upper is item (top times size plus left plus step) of grid. The lower is item (bottom times size plus left plus step) of grid. The western is item ((top plus step) times size plus left) of grid. The eastern is item ((top plus step) times size plus right) of grid. If upper is 0, set good to 0. If lower is 0, set good to 0. If western is 0, set good to 0. If eastern is 0, set good to 0. If good is 1 and side times side is more than best, set best to side times side.
Show best.
Expected stdout
9