res
to store the flower type for each garden, with a default value of 0 (unassigned).i
from 1 to n
:
a. Create an array colors
to keep track of the colors used by the neighbors of garden i
.
b. Iterate through the neighbors of garden i
and mark their flower types in the colors
array.
c. Find the lowest number flower (1 to 4) that is not used by the neighbors and assign it to garden i
.res
array containing the flower types for each garden.