Google | Phone | Finding squares in a 2D grid
Anonymous User
3382

I was asked this question in Google telephonic round. Problem is to find number of squares in a 2D grid. I was asked to assume input, so I assumed a 2D grid of 1s and 0s, with 1st representing edges and 0s representing empty spaces. Squares are formed of grid lines running horizontal and vertical only. I gave a solution to keep a list of intersection points, and building squares (by moving right on top edge and down on left edge, then down on right edge and right on bottom edge). I coded most of it during the interview. The interview didn't say much about the approach. I have few questions -

a) Is my input correct or would you represent it in a different way given the solution in mind?
b) My approach seems brute force but is there better way to see the problem?

Comments (6)