You need to sign in or sign up before continuing.×
5 kyu

Minimum path in squares

106 of 425Frederikbh
Description
Loading description...
Dynamic Programming
Algorithms
  • Please sign in or sign up to leave a comment.
  • trashy_incel Avatar

    In the above example the minimum path would be:

    although it can be deduced, it should be mentioned that this is the minimum path to reach the bottom right. It is important, since we are provided with a target point and it is not always the bottom right.

  • saudiGuy Avatar

    description should be language-agnostic.

  • ahmet_popaj Avatar

    Really funny kata on dynamic programming and algorithms optimization.

  • Konstantin Modin Avatar

    I used dynamic programming with memoization, but still got an execution timeout with just 114 tests passed in JS. Any hints ?

  • bouchert Avatar

    I think the Python one needs tuning again. These close-to-the-borderline performance tests need regular retesting to make sure they're still reasonable, given the server's decreasing performance of late. If you're going to make efficiency a critical component of the solution, you can't afford to submit these and forget about them.

  • QKiryu Avatar

    Is it me or does djikstra work on java, but times out on python?

  • virtyaluk Avatar

    This description and reversed test-cases is utter trash. Better solving leetcode.

  • vl4deee11 Avatar

    Why is Y a row of the matrix and X a column ? this is logical for the XOY coordinate grid, but not logical for other tasks where X == row and Y == col. It would be nice to write this in the description.

    Thanks for this kata!

  • Tigerhub779 Avatar

    I could not do it recursively so I try another approach :)

  • user4472141 Avatar

    My solution fails only for the very big squares. It's probably something to do with the array reference issue, but I give up

  • jainyk Avatar

    I don't understand that at (4,2) if a minimum path of 21 exist, then why the answer is 24.

  • anter69 Avatar

    Python tests and/or the reference solution should be reviewed and adjusted: I could only submit my solution after several tries, when I got lucky and it didn't time out. I then tried the 5 top voted solutions, but all of them timed out.

    hint: try to precalculate all the results for the big tests and just read the results

  • dalinwanglhtz Avatar

    This comment has been hidden.

  • gkucmierz Avatar

    I think that title and description or tests of this kata should be changed. It looks like author forgot than minimal path can be also something like that below.

    [
        [1, 2, 3, 6, 2, _, _],
        [_, _, _, _, 3, _, _],
        [1, 5, 3, _, 9, _, _],
        [4, _, 2, _, 6, _, _],
        [7, _, 8, 4, 7, _, _],
        [2, _, _, _, _, _, _],
        [8, 4, 3, 9, 2, 5, 8]
    ];
    

    Tests in this kata are not checking for actual minimal path.

  • caleb731 Avatar

    A key part to this problem that makes it much easier is that you can only move right or down. If you could move in any direction(up, down, left, or right)how would you go about solving it. Would it be neccasary to calculate every possible path(which would probably become impossible with bigger arrays) or is there some other way?

  • rrhodes Avatar

    This comment has been hidden.

  • lechevalier Avatar

    This reminds me something from Project Euler..!

  • dendisol Avatar

    From the kata's task: "Coordinates are marked as x horizontally and y vertically." Then in the test task does not correctly consider "Assert.AreEqual (5, MinPathSquare.MinPath (smallSquare, 0, 1));". Starting from the condition of the problem x = 0 and y= 1. Number of rows = x = 1; Number of columns = and y = 2; Therefore, the minimum path can be calculated only horizontally and it is equal to 3. But you consider the minimum vertical path that you have equal to 5. That is, you think as though two rows of the array are given, but x = 0, and this is one line. I think that the answer should be 3. According to the test example "Assert.AreEqual (5, MinPathSquare.MinPath (smallSquare, 4, 2));" I think that the answer is 21, not 24, if x = 4, and y = 2 Please explain how you calculated the minimum path.

  • tembl4 Avatar

    Solved this problem, using recursion, my computer thinks everything is fine, and in tests does not pass due to the delay more than 12 seconds, help you how to send a decision?

  • NIaa Avatar

    I think changing the description as follow is better. Because in this way, parameter x and y are nolonger needed. Which makes this kata more concise. "Your job is to calculate the minimum total cost when moving from the upper left corner to the lower right corner".

    Btw, I wonder why is this kata 5kyu since "Pyramid Slide Down" is 4kyu. Obviously this one is a little more difficult. https://www.codewars.com/kata/pyramid-slide-down/python

  • swittkopf Avatar

    Because the grid is reference type, each run is not independent of the last as you are passing in the same grid for many tests. As such the tests will fail on subsequent runs if the data therein is manipulated unless the programmer starts by making a local copy of the grid on each run. This is out of spec. I suggest changing your testing methods such that every grid tested has a unique reference. It is a cool problem otherwise.

  • brunolm Avatar

    I made it work, just don't know how to make it past the timeout.

  • dcsmith Avatar

    Nice kata! The dynamic programming tag tipped me off on how to solve it ;)