Find the shortest path from source to destination in a directed graph with positive and negative edges, such that at no point in the path the sum of edges coming
I would use recursion brute forcing here: something like (pseudo code to make sure it's not language specific)
you will need:
you will do:
function(int xPosition, int yPosition, int steps)
{
if(You are at target AND steps < Shortest Path)
Shortest Path = steps
if(This Position is NOT legal)
/*exit function*/
else
/*try to move in every legal DIRECTION, not caring whether the result is legal or not
but always adding 1 to steps, like using:*/
function(xPosition+1, yPosition, steps+1);
function(xPosition-1, yPosition, steps+1);
function(xPosition, yPosition+1, steps+1);
function(xPosition, yPosition-1, steps+1);
}
then just run it with function(StartingX, StartingY, 0);
the shortest path will be contained in the static external int