Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
The description says each word and the example case is alreadly self-explanatory
This comment is hidden because it contains spoiler information about the solution
323 (17 x 19) and 361 (19 x 19) aren't primes
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.
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.
That changes nothing but test modified.
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.
The kata description says that m > 2 but there is a test with m = 2.
A tip: You can use the following to loop through characters in a string (or elements in a list, etc.):
I think it would help a lot if we could see your code.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
How would you improve it?
Good one :D
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...