/connected-colors

Find the maximum amount of neighbors of an item in a grid.

Primary LanguageKotlin

connected-colors

Connected colors is a algorithm riddle which I read about somewhere on the Internet but forgot where exactly. Nevertheless, it would be nice to solve this problem.

Given a grid (nxm) filled with colors, return a map of all colors inside the grid with their maximum number of connected occurrences.

A color of a cell is connected if another neighboring cell contains the same color.

Example

R, B, Y, B, R
B, Y, Y, R, Y
R, B, Y, B, B
R, B, Y, R, Y

Output:

B=4
R=2
Y=5