I'm solving "Unknown amount of duplicates. One missing number.":
In this kata, we have an unsorted sequence of consecutive numbers from a to b, such that a < b always (remember a, is the minimum, and b the maximum value). They were introduced an unknown amount of duplicates in this sequence and we know that there is an only missing value such that all the duplicate values and the missing value are between a and b, but never coincide with them. Find the missing number with the duplicate numbers (duplicates should be output in a sorted array)
I'm using this code:
def find_dups_miss(arr):
m = max(arr)
n = min(arr)
a = list(range(n, m+1))
d = list(set(a).difference(arr)) # creates the list with the missing element
z = sorted(set([x for x in arr if arr.count(x) >= 2])) # creates the list with duplicate elements
return d + [z]
but it timeouts since it exceeds the 12000 ms time limit.
What can I do to make it run faster?
an unknown amount of duplicateslen(sequence) - a + b (-1 because b supposedly inclusive +1 because one missing) \$\endgroup\$