As noted by ARcard, it might be helpful to add to the problem description that the parameter 'functions' can't be altered by your function in any way, or the random tests fail. Otherwise, really nice kata!
Small Python Tip!
checkout closures and after that its pretty easy.
Good work !
For js a small hint:
Even if you dont understand it at first, just give you some time, you will eventually solve it.
This kata is really worth to solve beacuse it will teach you this two important topics of js
because it's a list comprehension
why is inside a square bracket?
Just a quick question, WTH is that?
damn. Practically the same as mine. Nice.
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 yours is O(n^2) for worst case too, because once you look at all the chars of text, then you check all the elements of your dict.
I know it's been said, but it bears repeating until something changes:
The difficulty is too high for being 6 kyu!
Here is a good article to learn about time complexity:
Here you can see the time complexity of different methods of Python builtin data structures:
hi there ,
A newbie here. I have learned some basic of python language. can you suggest how /where should i start learning abt the Complexity O of the programs