Ad
  • Default User Avatar

    I see two issues:

    1) Java methods and attributes usually start with lower case letters, so it should be .startsWith(...), .endsWith(...) and .length in your code.

    2) You don't check for noses of the smiley faces.

  • Default User Avatar

    It's a reasonable way to make the if statement in the for loop work correctly for the very first prime it finds. Since n is the upper bound for the range, i - previous_prime is nonpositive and thus can't equal g, which is want we want.

  • Default User Avatar

    The kata description says that m > 2 but there is a test with m = 2.

  • Default User Avatar

    A tip: You can use the following to loop through characters in a string (or elements in a list, etc.):

    for char in s:
        # char contains a single character of s in each iteration of the loop
    
  • Default User Avatar

    I think it would help a lot if we could see your code.

  • Default User Avatar

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

  • Default User Avatar

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

  • Default User Avatar

    How would you improve it?

  • Default User Avatar
  • Default User Avatar

    I am amazed that this problem could have been done in one line.

    That said, I think there is a lot of unnecessary work done because the if clause has to travel through the input string multiple times (once for each unique character).

    However, I don't think the solution is O(n^2) as a few people have suggested. I believe it's O(n) instead. We start by making a set from the input string, which is O(n). Then we iterate the set (O(1) because it is bounded in size - it can't have more than 36 elements) and for each iteration walk through the whole input string (O(n)), which gives O(1) * O(n) = O(n). So in total the solution is O(n) + O(n) = O(n).

  • Default User Avatar

    I believe that shaunpatterson's solution is O(n). The counting of occurences of each character with the for loop is O(n). Then we traverse the (character, count) pairs to find the characters that appear more than once. This is O(1) because there is at most 36 characters (26 alphabets and 10 digits). Finally, we count the characters that appear more than once, which is again O(1). So we have that the whole thing is O(n) + O(1) + O(1) = O(n).

  • Default User Avatar

    I think a clarification on what is meant by capitalisation might be a good idea - should 'LinkedIn' turn into 'Linkedin' after capitalisation?

  • Default User Avatar

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