Fill up to duplicate ranges Let \$L\$ be a list of positive integers with no particular ordering, and which can contain duplicates. Write a program or function which outputs a list of positive integers \$M\$ (whose ordering is unimportant) such that merging \$L\$ and \$M\$ results into the smallest list which can entirely split into identical ranges of integers \$[1..i]\$, where \$i\$ is the biggest element in \$L\$

Example

Let L = [5,3,3,2,7]. The maximum element of L is 7. The most times a specific integer occurs is 2 (3 appears 2 times). Therefore, we need to output the list M that will allow to complete L so that we can construct 2 ranges of integers from 1 to 7.

Therefore, we need to output M = [1,1,2,4,4,5,6,6,7], so that each integer from 1 to 7 appears 2 times.

Inputs and outputs


Use anything in your language that is similar to lists. The data structure used for the input and the output must be the same.
The input list will contain only positive integers.
The input list will not be empty.
You cannot assume the input list is sorted.
The ordering in the output list is unimportant.


Test cases

Input                  Output
[1]                    []
[7]                    [1, 2, 3, 4, 5, 6]
[1, 1, 1]              []
[1, 8]                 [2, 3, 4, 5, 6, 7]
[3, 3, 3, 3]           [1, 1, 1, 1, 2, 2, 2, 2]
[5, 2, 4, 5, 2]        [1, 1, 3, 3, 4]
[5, 2, 4, 5, 5]        [1, 1, 1, 2, 2, 3, 3, 3, 4, 4]
[5, 3, 3, 2, 7]        [1, 1, 2, 4, 4, 5, 6, 6, 7]


Scoring

This is code-golf, so the shortest answer in bytes wins.
Perl 6, 37 33 bytes

-4 bytes thanks to nwellnhof!



{^.keys.max+1 xx.values.max∖$_}


Try it online!

Anonymous code block that takes a Bag and returns a Bag of values.

Explanation:

{                             } # Anonymous code block
 ^.keys.max+1  # Create a range from 1 to the maximum value of the list
              xx  # Multiply the list by:
                .values.max      # The amount of the most common element
                           ∖$_   # Subtract the original Bag