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.
No, it is not. Check in my other solutions. There is a faster one.
5572ms when I submit, test cases work fine
This comment is hidden because it contains spoiler information about the solution
Strictly speaking, since there are only two unique values (guaranteed by the description), set will have len 2, thus O(1) memory consumption.
In description:
This comment is hidden because it contains spoiler information about the solution
See the comments below, this implementation is correct as far as A is a list of unique integers.
Unique is an important detail. The devil is in the details.
The example you provided doesn't fit this requirement as 3 is not unique...
You're not to test whether the input is a mersenne prime
Set has a time complexity of O(n) in best, worst, and average cases. Even the most efficient sorting algorithm only has a time complexity of O(n) when the data is already sorted.
Solutions which do not leverage set are less time efficient than this solution. The only actual improvement I've seen suggested is Blind4Basics' fork of this solution which only checks the first three numbers of the array, despite the many comments to the contrary. Test it. You'll see it's faster than whatever alternative solution you have in mind. (If it's not, please show me, I'd love to see it.)
Python is a high-level language. Unless you're willing to do a deep dive into the internals, you can really only make an educated guess of the time complexity. Here
set
is doing a lot of the work directly in C. This more than makes up for going over the data more than once.You're welcome.
I think the 21 is added two times in your code. I had the same problem ;-)
You are wrong, the first order breaker is 0 of [1, 2, 0, 3, 4]. 2 is not even an order breaker.
As i described in details, Breaker is the item, when removed from sequence, sequence becomes ordered by ascending.
I am not following what you wrote. Can you provide a test case which fails my code?
We can add it into the test suite as well.