Background
A Young diagram is a diagram that represents a nonincreasing sequence of positive integers using left-justified rows of squares. As an example, 5, 4, 1
is drawn as
OOOOO
OOOO
O
A Young diagram is said to be symmetric if it is identical to its transpose (reflection along the NW-SE diagonal). The above diagram of 5, 4, 1
is not symmetric, since its transpose represents 3, 2, 2, 2, 1
instead:
5 OOOOO 3 OOO
4 OOOO 2 OO
1 O => 2 OO
2 OO
1 O
A symmetric example is that of 4, 2, 1, 1
:
OOOO
OO
O
O
Challenge
Given a nonincreasing sequence of positive integers, add as few numbers as possible to the front of it so that its Young diagram becomes symmetric. If the input is already symmetric, your code is expected to output it as-is. You may take input and give output in reverse order (numbers in increasing order; e.g. [1, 1, 2, 2] -> [1, 1, 2, 2, 4, 6]
).
Standard code-golf rules apply. The shortest code in bytes wins.
Test cases
[1] -> [1]
[2] -> [2, 2]
[3] -> [3, 3, 3]
[1, 1] -> [3, 1, 1]
[2, 1] -> [2, 1]
[3, 1] -> [4, 3, 3, 1]
[2, 2, 1] -> [5, 4, 2, 2, 1]
[3, 2, 1] -> [3, 2, 1]
[4, 2, 2] -> [4, 4, 2, 2]
[4, 2, 1] -> [6, 5, 4, 4, 2, 1]
[4, 4, 3] -> [4, 4, 4, 3]
[5, 4, 1] -> [6, 5, 5, 5, 4, 1]
[4, 2, 1, 1] -> [4, 2, 1, 1]
[2, 2, 1, 1] -> [6, 4, 2, 2, 1, 1]
[9,2]
the jump here is big enough it caused my attempt to fail whereas none of the existing cases did. \$\endgroup\$