Chocolate Distribution Program

Manoj is a teacher in a government school. He has 10 students in his class sitting in a straight line, which he represents as array elements, now he wants to distribute chocolates to all of them. So he devices a algorithm where students compete with one another to get chocolates from Manoj. Having chocolates is represented as 1 and not having chocolates is represented as 0. if the student is at a[0] or a[last] position they only have one neighbour thus, in this case consider such non existent neighbours to be not having any chocolates.

Algorithm looks something like this: If on any given day, if a student’s neighbours(both on left and right)

  • Both have chocolates or both don’t have chocolates

Then, he will get chocolates the next day.

INPUT:
[1,1,1,0,1,1,1,1,],2

OutPut VALUE:
[0,0,0,0,0,1,1,0]

TESTCASES 1:
INPUT:
[1,0,0,0,0,1,0,0],1
EXPECTED RETURN VALUE:
[0,1,0,0,1,0,1,0]