Go from source to destination in 2d matrix with min steps collecting all candies. How to do it?
The fact that the total number of candies is at maximum 12 is an important constraint.

Let the candies and start and end points (total &lt;=14 points) be key points in the grid. Now use BFS from each of the key points to find the distances between the key points, and form a new graph with only the key points. Since the number of nodes in the new graph is so small, we can use Travelling Salesman on this new graph to solve the problem.

(Note: You will need to slightly modify Travelling Salesman to work for this specific problem.)