Extension of the wonderful Problem 1049 (Path of Least Resistance).
A matrix is given as input. You have to take a tour starting from the top left corner to the bottom right corner of the matrix. You can move to any one of the adjacent 8 elements. Return only the sum of the elements in your path.
Example :
Input = [1 9 1 1 9 1 9 1 1 3 9 1 9 9 8 1];
Output = 7;
Here, the least-sum path though the matrix is shown below with asterisk(*):
[1* 9 1* 1* 9 1* 9 1* 1 3 9 1* 9 9 8 1*];
Return only the sum of the elements along the path. I will add robust test cases time to time WITHOUT re-scoring existing solutions.
I don't understand how this works with negative elements. For example if the input matrix is [0 -1;0 0] it is possible to obtain an arbitrarily low score by going [EastWest] sufficiently many times then EastSouth.
yeah... deleted the negative elements.. was foolish of me to think that way
The eye matrix is tricky - i must admit i cheated.. there is a of torugle with branching, i tried developing algorithm do "look up front" but failded...
I get 11 for test case 2.
May be you are considering the element at the bottom left corner. But, it is not necessary since diagonal movement is also allowed
OK, you're right about test case 2. I was wrong. But I get 6 for test case 1, not 7. The shortest path does not include upper right corner.
yeah, that is wrong.. corrected and thanks. too many mistake in a single problem
91 Solvers
Poker Series 01: isStraightFlush
92 Solvers
Return unique values without sorting
483 Solvers
189 Solvers
36 Solvers