Flood-fill (1-d dp)

i did not understand , how to fill color of square, we fill only connected component or any index…,
please help me,