Samsung Electronics interview question

BFS in a 2d matrix