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.
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.
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).
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).
I think a clarification on what is meant by capitalisation might be a good idea - should 'LinkedIn' turn into 'Linkedin' after capitalisation?
This comment is hidden because it contains spoiler information about the solution