The problem with this approach is that you're calculating the cost of every possible path in the matrix. As you can imagine, that is quite a lot of possibilities. There is a much smarter way solve this problem, that gives you a running time of O(n^2) if the matrix is quadratic (Hint: Dynamic programming).

This comment is hidden because it contains spoiler information about the solution

This solution would "just traverse down". The loops uses the destination coordinates to avoid unnecessary calculations.

`X`

denotes the column of the endpoint, or the horizontal point if you will.`Y`

denotes the row of the endpoint, or the vertical point if you will.With coordinates

`(0, 0)`

it should be obvious why the minimum path is`1`

, since you're starting and ending at the same position with the value`1`

.Here is the minimum path of the grid given before, when the endpoint is in

`(0, 1)`

:You always start at the upper left corner. Then, each nested array represents a row in the 2D-grid.

In the test-case you're referencing you're given the following grid:

The end coordinate is

`x = 0, y = 1`

, which is where the`4`

is in the grid. Therefore the minimum path will be`1 + 4 = 5`

.The problem with this approach is that you're calculating the cost of every possible path in the matrix. As you can imagine, that is quite a lot of possibilities. There is a much smarter way solve this problem, that gives you a running time of O(n^2) if the matrix is quadratic (Hint: Dynamic programming).

That's intentional as to not clutter the test cases.

The tests have been made in a way that requires you to come up with an implementation that runs pretty fast. (Hint: dynamic programming)

You're not always asked to move to the lower right corner. The goal-coordinated can be any point in the grid.

Oh yeah. That should be fixed now. I've allowed the very big squares to be reused, as it would take to long to copy them.

You're right. I've made the individual tests copy the original grid, to fix this. Thanks for pointing that out.

Fixed.

I've changed the order now. Thanks for the feedback!

I really can't see where they're in the wrong order, please specify.

Thanks for the feedback!

I've added units to the input specifications.

Missing test cases in Java

## Loading more items...