Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
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 is1
, since you're starting and ending at the same position with the value1
.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 the4
is in the grid. Therefore the minimum path will be1 + 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...