Ad
  • Custom User Avatar

    This solution does not honour "If there are less than n occurrences of the substring, return -1". It will fail e.g. for FindOccurrence.findNthOccurrence("a", "aaa", 5) where it returns 0 instead of -1.

  • Default User Avatar

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

  • Custom User Avatar

    If you want to go functional - do it the whole way. The loop and the mutable result array are very ugly...
    I would not call this "best practice" at all.

  • Default User Avatar

    Looks like a solution you'd see in Haskell, JS or Ruby with the use of map and filter. I don't usually think of Java as functional, but I'm obviously wrong. Very nice.

  • Custom User Avatar

    The algorithmic complexity of the code is atleast linear, but the required complexity is lower than linear.

  • Default User Avatar

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

  • Default User Avatar

    Why O(n) doesn't fast enough?

  • Default User Avatar

    For most katas, may be. But there are katas with certain demands to the code itself. Maybe I just overthought it. Anyway - there is a mistake in the placeholder.
    UPD: I managed to put the solution between 'return string' and ';', so it is possible to solve without changing the placeholder, thus the task is correct, but a bit tricky.

  • Custom User Avatar

    Oh, the code you see in "Initial Solution" box is meant to be completely replaced by your solution. The fact that it returns the same reference it accepts does not mean that you have to do it this way, it's just an example and placeholder. You can do it any way which passes tests, and as you noticed, in Java you cannot mutate the original string. You have to create new one.

  • Default User Avatar

    This:
    class Kata {
    static String alternateCase(final String string) {
    return string;
    }
    }
    UPD: However, I've made some research and learned something from this, so it's not in vain.

  • Custom User Avatar

    You are right, you cannot mutate a string in Java. This kata cannot be solved by mutating the string neither in Java, nor in many other languages, but it can in some others

    So, accoring to the task, we have to mutate given string.

    Which part of the task makes you think that this have to be exactly the solution here?

  • Default User Avatar

    Java
    Given is the final String and the same String to return. So, accoring to the task, we have to mutate given string.
    I didn't find the way how to do that and looked at the solutions. All of them return another Strings. And they are considered done!

    It's so frustrating.

    Question to the author: How to mutate final String in Java if Strings are initially immutable?

  • Default User Avatar

    I forgot to delete the row reverseRoute[0] = "Begin " + arr[arr.length-1].split(" ", 2)[1]; so I initialized reverseRoute[0] twice. I'm not sure whether there is an option to edit solution or only add an alternative.

  • Default User Avatar

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

  • Custom User Avatar

    I just tried your code in a fork and never had any problems, though... :o (apart from the fact that I don't know how you did submit this version since it doesn't compile (unsafe opeartion because you didn't decalre the type the list is holding) x)

  • Loading more items...