Ad
  • Custom User Avatar

    The description says each word and the example case is alreadly self-explanatory

  • Default User Avatar

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

  • Custom User Avatar

    323 (17 x 19) and 361 (19 x 19) aren't primes

  • Default User Avatar

    For gap(8,300,400). I am getting following error : [323, 331] should equal [359, 367] 323-331 is the first prime pair with a gap o 8. 359-367 has 361 prime number in between.

  • 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

    That changes nothing but test modified.

  • 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).

  • Loading more items...