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.
Counter(arr).items()
returns a list of[(key1, value1), (key2, value2), ...]
where the keys are the distinct numbers inarr
and the values are the occurrences of that key inarr
. You can pass this into themax
function with a customkey
to retrieve the max value. The key takes in a(key, value)
instance and compares it against other elements by first comparingx[1]
thenx[0]
wherex[1]
is the occurrence of that number andx[0]
is the number as stated before. You need to apply[0]
to the outputted(key,value)
of the max function to obtain the distinct number.normally efficiency. But here, it's done in a pretty stupid way, which makes this solution even slower than the O(n²) solution without the set... XD
=> See the fork.