We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Here is a shorter variant in Python3 that uses a frequency dictionary of sets rather than of ints. I was inspired by fromtheeast1's use of a frequency dictionary f, which prevents a timeout on the longer query lists. This success is due to a dict's or set's find-by-value time being O(1) average and O(n) worst, whereas a list's find-by-value time is O(n) average.
Frequency Queries
You are viewing a single comment's thread. Return to all comments →
Here is a shorter variant in Python3 that uses a frequency dictionary of sets rather than of ints. I was inspired by
fromtheeast1
's use of a frequency dictionaryf
, which prevents a timeout on the longer query lists. This success is due to a dict's or set's find-by-value time being O(1) average and O(n) worst, whereas a list's find-by-value time is O(n) average.