17
Abe Dillon
Last seen 5 years ago
Member for 9 years, 3 months, 18 days
Difficulty Normal
O(n^2) complexity is very sub-optimal for this problem. Checkio should have added tests with very long lists to highlight the performance problems with this solution.
assert checkio(list(range(100000))+[0])) == [0, 0], "big list"
Takes over 2 minutes on my computer using your solution. While an O(
More
I want to say that while this is concise and the use of lambda is creative, this solution has a pretty awful time complexity of O(n^2). Normally, I prioritize clarity over optimization, but it pains me to see the [x for x in d if d.count(x)>1] solution tagged as speedy so often. This being an educat
More
I'm giving this a thumbs down for miscategorization. While it is true that this is quite easy to read, it would much more fitting to tag it as "speedy".
(just kidding! thumbs up!)
More
I think this should be tagged as "creative" rather than "clear". It's a very cool solution, but if you write code like this in a workplace (particularly the `corners` method) people will hate you.
More
Computers are very good a simple repetitive tasks, so when you find yourself repeating simple code so much, it's a good sign you can simplify things. Languages like Python offer tons of tools for capturing repetition: data-structures, loops, functions, classes, etc. In this case you're using variabl
More
this has a time complexity of O(n^2) because data.count(x) visits each item in the list (O(n)) and is evaluated n times.
More
the time complexity of this solution is O(n^2) because data.count(x) visits each item in the list (complexity O(n)) and you call data.count(x) n times. The fastest possible solution to this problem would have a time complexity of O(n), which means if you got a list of 1,000,000 items your solution w
More
This is a good solution that actually achieves O(n) complexity instead of the O(n^2) complexity of many of the "speedy" solutions for this problem. I am curious why you used 'c = __import__("collections").Counter(data)' instead of 'from collections import Counter'.
More
Good solution! The collections module has a 'Counter' class that does the same thing as the first three lines of your code.
More
this is pretty awesome! the use of `or` to perform your sort before calculating the mean is neat and the +/- indexing trick is fun, but the bitwise inversion of -len(d) was incredibly tricky! I hope you don't write production code this sneaky!
More
This is a good solution. You should check out the Hitchhiker's Guide to Python. Looping over indexes isn't very Pythonic. Something like the following would be much cleaner:
if len(data) < 10:
return
flags = [False]*3
for c in data:
flags[0] |= c.islower()
More