A few days after you paint the chess board in Queen Square
, an admirer invites you to the Game Park, where he has a n x n square game board set up. Some of the squares have pieces on them, but most of them are empty. The admirer wants to completely paint some adjacent empty squares such that they form the largest empty square on the game board.
Given the game board as a binary grid with 1=piece and 0=no-piece, what is an O(nē) algorithm to find the largest empty square?
(The notation O(nē)
refers to the algorithm speed for large n.)
(In reply to Solution
First of all , Hi to all, I am newbie here.
Great solution joel. I guess it works for a largest nonoccupied square area.
I just had different kind of problem than actually stated. I was asked to find largest square whose all 4 sides are continuous. The squares within it, could be occupied.
I guess it could be as easy like this one but certainly seems formidable for me.
Posted by Niranjan
on 2007-02-12 05:49:28