At the North Pole, theyโve set up a panel of Christmas lights ๐โจ to decorate the workshop. Each light can be on with a color, or off.
The panel is represented as a matrix where each cell can be:
'.' โ light off'R' โ red light'G' โ green light
The elves want to know if there is a line of 4 lights of the same color that are on and aligned on the panel (only horizontal โ or vertical โ). Lights that are off ('.') donโt count.
hasFourLights([
['.', '.', '.', '.', '.'],
['R', 'R', 'R', 'R', '.'],
['G', 'G', '.', '.', '.']
])
// true โ there are 4 red lights horizontally
hasFourLights([
['.', 'G', '.', '.'],
['.', 'G', '.', '.'],
['.', 'G', '.', '.'],
['.', 'G', '.', '.']
])
// true โ there are 4 green lights vertically
hasFourLights([
['R', 'G', 'R'],
['G', 'R', 'G'],
['G', 'R', 'G']
])
// false โ there are no 4 lights of the same color in a row
Note: The board can be any size. No diagonals.