implemented neighborsWithHistory method of Solver class