There is a bug in the code. For ex, If 8 and 2 are placed in the grid with one empty space between them. and if we place 4 between them. Then it creates problem.