Ad
  • Default User Avatar

    There are 6 code variations, all of them with removed lines

  • Default User Avatar

    Single exit strategy is a controversial discussed dogma. For instance the Object.equals() method uses multiple return statements. Just have a look at the source code. Perhaps you shall advise Oracle that you think they're using bad pracice and improve the Java code base with a better solution. Your approach may be good for these concrete kata, but it is indeed not a general valid way, to solve all problems of that type, as you can see.

    Hence, my question was not about linking connections to anything, but wanting to know, how you would solve problems of that kind in general, if something like IntStream was not accessible. Since clairvoyance does not exist, nobody can elaborate how your solution would look like. This is just a red herring argument. I would be grateful, if you could take two minutes to show a good way that works even for cases when Streams don't work, with a single exit point. And of course, without a break in the loop, because it violates your choosen strategy.

  • Default User Avatar

    How would you solve it without any imports like IntStream?

  • Default User Avatar

    To enhance fastness, it would be better to convert the String to StringBuilder, do the replaces like we did with String, and then convert the SB back to String. But it would still remain in O(n), thus it may not be worth the effort, but is nice to know.

  • Default User Avatar

    Both solutions are in the same complexity class O(n). So it's not really a win to use a for loop, instead of just replacing several times. Your code has also a bad readability, and is therefore less maintainable in production.

    Our method will not be slow like you say, only somewhat slower than yours --> See big O notation: https://en.wikipedia.org/wiki/Big_O_notation

  • Default User Avatar

    By using so many languages, it's not a surprise you can't remember syntax and libraries. It may be better to master a language and then change to another one, instead of "using" lots of languages without even knowing/remembering the basics.

    It would be the same, if a person claims to speak 5 languages, but then needs a dictionary to ask a simple question. Sometimes, less is more...

  • Default User Avatar

    Don't give a shit about those losers. Coming here to earn honor instead of learning to program, is not a way to success.

    Don't compare to others, compare just to yourself.

  • Default User Avatar

    It is because some testcases expect false instead of true. (They are not all true...) The runtime error will always appear if true or false are hardcoded. Read the error message to localize the certain line of the failing testcase, or print the input.

  • Default User Avatar

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

  • Default User Avatar

    What about this example test case for Java? It contradicts your statement...

    assertEquals("Halifax, Montreal, Toronto, Chicago, Winnipeg, Seattle",
    routes.findRoutes(new String[][]{{"Chicago", "Winnipeg"}, {"Halifax", "Montreal"}, {"Montreal", "Toronto"}, {"Toronto", "Chicago"}, {"Winnipeg", "Seattle"}}));

  • Default User Avatar

    God is the creator of Humans, and has no inner Human class, because no human is a god. Try it with three separate classes, and it should work fine. You just need to know the minimum about classes and inheritance to complete the task.

  • Default User Avatar

    I really like your approach with the string array. It should be much simplier than my solution with bigger amount of outputs.

    return list.size() == 0 ? "empty" : list.size() == 1 ? "singleton" : "longer";

  • Default User Avatar

    You're right. As every card only appears once, there is no necessity to blank sorted cards.