Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more
  • 26301880?v=4

    @JJar could you please reply with your code? It doesn't display properly when I click on view solution to your comment.

  • Profile pic

    I just compared the commented code to code by @IonutArhire.

    On my computer, the commented code took 15.5 seconds to exicute on an array with 500'000 elements of length 4 and k = 1000. Code by IonutArhire took 0.081 seconds. I am amazed by the difference!

    My code took 0.71 seconds which is 20 times faster than the commented code, but still 10 times slover than the code of @IonutArhire.

    @IonutArhire, could you please let me know why your code is so much faster than mine?

  • 42543722?v=4
  • 31668662?v=4

    The fact that you can move diagonally doesn't mean that you have to. Also, duplicate issue.

  • 39525905?v=4
  • 39519932?v=4
  • Profile pic

    There are multiple shortest routes.
    For example:
    It can be [[5,5],[5,6],[5,7]]
    It can also be [[5,5],[4,6],[5,7]]
    Because in this situation,you can go diagonally.

  • 26301880?v=4

    I was referring to the redundancy of declaring an additional variable and I am right regardless of the low-level implementation. However, we shouldn't throw words around, so please, enlighten me how declaring a variable and assigning it an object doesn't use memory allocation :D

    You say I make bogus claims but I don't see you bringing any arguments to the table, so I'm going to categorize your unfounded claim to also be a "bogus claim" :D

  • 26301880?v=4

    I was just addressing one property of "best practice" code because it's only that property that that code blatantly violates. Naturally, I wouldn't have brought it up if the trully efficient solution was a hard-to-write hard-to-understand mess, but it's not the case (6 kyu problem, get real). It's nice that you talk about real life code, and I fully agree, it depends on the context. However, if you pay attention, there is only one "best practices" button, there's no "best practices for (insert git repo)", so we're talking generally, and generally, efficiency matters (as I said before, the efficient method is not hard to understand and or write). The link is for beginners, and I myself looked up stuff about javascript low-level implementation because I'm not experienced with this language and I don't want to talk without knowledge.

    "It's not like anyone has problems seeing the time complexity there" (by you)

    That's an arrogant thing to say. Not everyone learned programming from university + a lot of people start with web programming which doesn't really involve complexity talk (not at a beginner level at least).

    It's obvious that you don't like me, but please, be more friendly next time, not for me, but for those reading, they shouldn't be subjected to this toxic comment of yours.

    Look, I personally think you are a competent programmer, but what I don't like about you is that you are dumb as a person. Your whole premise is flawed, because you don't understand the context (read my first paragraph if you're confused). You only care about being right, not about learning new things, that's why you don't give me or anyone else the benefit of the doubt.

    I'm done here, if you got something more to say to me directly don't exert yourself, I won't read it (just cry to a friend about it or something I don't care).

  • 14909989?v=3

    There is no such a concept of "allocating space for a variable" in any high level languages that is not C/C++. Please learn the language you're using properly before making bogus claims ;-)

  • 14909989?v=3

    Okay, first:

    Best practice code means code that you would feel comfortable using in production environment which means the code should be efficient.: [citation needed]

    Second, time complexity talks are always appealing to beginners ;-), but the thing is, if you're trying to do it with the best performance, the code will also be much more complex and complicated which means more room for errors and bugs; and even more, the "readability" guys will storm in and yell at you for writing "unreadable" and "unmaintainable" code which are clearly "not best practice" ;-)

    Any experienced coder knows that there is always a tradeoff: Do you really need that performance? (Sometimes the bottleneck is at somewhere unrelated to your code, so even optimizing will not give you any benefit at all) If not, why not write shorter and simpler code instead? Code quality is not black and white, there is no single "right" or "wrong" (and claiming about that by complaining about "short code" or "code that uses non-trivial language features" are signs of the speaker being a noob); but the great coders know about a thousand ways to solve a problem, their relative merits, and choose the one that best suits the situation at hand.

    p.s It's not like anyone has problems seeing the time complexity there, so the link is not very helpful. Or maybe it's just you? Well, then it's you who should learn more, right? ;-)

  • 26301880?v=4

    I see this solution has the most "best practices" votes. For any beginners reading, this is not a best practice solution. Best practice code means code that you would feel comfortable using in production environment which means the code should be efficient. This code runs in roughly n * 2k time (each slice() call takes k time and each join() call takes k time) which isn't the most efficient for the problem at hand.

    Here's a beginner level short article I found for getting started with understanding time complexity in javascript : https://www.pdiniz.com/time-complexity-of-javascripts-built-in-methods/

  • 26301880?v=4

    You're not missing anything, he allocates an additional variable for nothing.

  • Profile pic

    55 and no more ideas :(

  • 16988960?v=4
  • Loading more items...