Back to problems

Count Same-Color Squares in an Unbounded Grid

Algorithm · Waymo · Medium

Requirements Input: a two-dimensional collection of cells, where every present cell has a color chosen from a small constant palette such as A, B, C, or D. The grid has no predetermined size limit, so handle it as a sparse set of coordinates instead of allocating a bounded rectangular matrix. Output: return how many axis-parallel squares consist entirely of one color and whose cells belong to a single region connected through up, down, left, and right neighbors. Notes A…

Checking your access…