[Question]
  [
## Background
A [**Young diagram**](https://en.wikipedia.org/wiki/Young_tableau#Diagrams) 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](/questions/tagged/code-golf "show questions tagged '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]
```
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~25~~ ~~24~~ ~~21~~ 19 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
g+√†LZ–∏√¶√©‚Ç¨√¨.ŒîD√Ö10Œ∂OQ
```
Brute-force approach. Times out for most inputs.
-2 bytes thanks to *@ovs*.
[Try it online](https://tio.run/##AS0A0v9vc2FiaWX//2crw6BMWtC4w6bDqeKCrMOsLs6URMOFMTDOtk9R//9bMSwgMV0) or [verify some of the shorter test cases](https://tio.run/##S0oszvifnFiiYKeQnJ@SqpdfnJiUmapgY6Pg6u/GZa@k8KhtkoKS/f907cMLfKIu7Di87PDKR01rDq/ROzfF5XCrocG5bf6B/2t1uEDKucozMnNSFYpSE1MUMvO4UvK5FBT08wtK9CGmQik0i2wUVMBq81L/RxvGckUbAbExEBvqgHlg0hjKhvEgtAmQNoLSEL6JDkinKZCGyRsidIJYAA).
## Previous answer: [05AB1E (legacy)](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~25~~ 24 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
√Ö1Œ∂O¬©[DN(.¬£I¬ÆgN-¬£Q#>}N¬£√¨
```
Port of [*@gsitcia*'s Python answer](https://codegolf.stackexchange.com/a/235185/52210), so make sure to upvote him/her as well!
-1 byte by switching to the legacy version of 05AB1E. The original program was `√Ö10Œ∂O¬©[D¬æ.$I¬Æg¬æ-¬£Q#>¬º}¬æ¬£√¨`, with the following differences:
1. -1 byte: `0Œ∂O` (zip with 0 filler; sum) is replaced with `Œ∂O` (zip with default space filler; sum), since the legacy version will ignore these spaces when summing;
2. -1 byte: The `¬æ` are replaced with `N` and the `¬º` has been removed, because `N` can be accessed outside of loops in the legacy version, which will reset to `0` in the new version;
3. +1 byte: `.$` wasn't a builtin yet in the legacy version, so we'll have to use `(.¬£` instead (`.$` is a[b:]; `.¬£` is a[-b:], and `(` negates the integer first).
[Try it online](https://tio.run/##ATMAzP8wNWFiMWX//8OFMc62T8KpW0ROKC7Co0nCrmdOLcKjUSM@fU7Co8Os//9bNSwgNCwgMV0) or [verify all test cases](https://tio.run/##MzBNTDJM/V9Waa@k8KhtkoKSfaXL/8Othue2@R9aGe3ip6F3aHHloXXpfrqHFgcq29X6HVp8eM1/nf/R0YaxOtFGQGwMxIY6YB6YNIayYTwIbQKkjaA0hG@iA9JpCqRh8oYInUBWLAA).
**Explanation:**
```
g              # Get the length of the (implicit) input-list
 +             # Add it to each value in the (implicit) input-list
  √†            # Pop and leave the maximum
   L           # Create a list in the range [1,max(input)+length(input)]
    Z–∏         # Repeat each integer this max amount of times
      √¶        # Get the powerset of this entire list
       √©       # Sort it by length
        ‚Ç¨√¨     # Prepend each in front of the (implicit) input-list
.Œî             # Find the first list which is truthy for:
  D            #  Duplicate the current list
   √Ö1          #  Map each integer in the list to a list of that many 1s
      Œ∂        #  Zip/transpose this list of lists,
     0         #  with 0 as filler to make it a rectangle
       O       #  Sum each inner row
               #  (we now have the reflection of the list)
        Q      #  Check if the duplicated current list is equal to its reflection
               # (after we've found a result, output it implicitly)
```
```
√Ö1             # Map each integer in the (implicit) input-list to a list of that many 1s
  Œ∂            # Zip/transpose this list of lists,
               # with a space as default filler to make it a rectangle
   O           # Sum each inner row, ignoring the spaces
               # (we now have the reflection of the input-list)
    ¬©          # Store this list in variable `¬Æ` (without popping)
[              # Start an infinite loop:
 D             #  Duplicate the current list
  N(.¬£         #  Remove the last 0-based loop-index amount of values from this list
      I        #  Push the input-list
       ¬Æg      #  Push the length of list `¬Æ`
         N-    #  Decrease it by the 0-based loop-index
           ¬£   #  Only leave that many leading items from the input-list
            Q  #  If both lists (¬Æ[cv:] and input[:len(¬Æ)-cv]) are now equal:
             # #   Stop the infinite loop
 >             #  If not, increase all values in the list by 1
}              # After the infinite loop: 
 N             # Push the (0-based) loop-index we ended at
  ¬£            # Only leave the index amount of values from the list
   √¨           # And prepend it at the front of the (implicit) input-list
               # (after which this is output implicitly as result)
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 21 bytes
```
+L}R·πó‚Å∏;‚Ç¨b1Z∆ë$∆á
0√ß1#·∏¢√ß
```
[Try it online!](https://tio.run/##y0rNyan8/1/bpzbo4c7pjxp3WD9qWpNkGHVsosqxdi6Dw8sNlR/uWHR4@X@dw@1HJz3cOQMonfWoYY6Crp3Co4a5XIfbgQKR//9Hc0UbxupwRRuBCGMQYaijABGB0sYIPpIQjGkCZhohmDBRIAIbZwpmIqk1RDUPxOOKBQA "Jelly ‚Äì Try It Online")
A full program taking a list of integers as its argument and printing the shortest list satisfying the requirements. The TIO link includes all test cases.
## Explanation
### Helper link
Left argument is the number of additional digits to prepend, right argument is the original list
```
+               | Add:
 L}             | - Length of original list
   R            | Range 1..this
    ·πó‚Å∏          | Cartesian power with number of new digits
      ;‚Ç¨        | Prepend each to the original list
        b1Z∆ë$∆á  | Convert to unary and test whether unchanged by transposition
```
# Main link
```
0√ß1#           | Starting with zero, identify how many additional digits are needed to make the list meet the requirements
    ·∏¢          | Head
     √ß         | Then call the helper link again one last time
```
---
# An alternative [Jelly](https://github.com/DennisMitchell/jelly) answer uses less brute force, 21 bytes
```
b1S+‚Åπ·∏£…ó‚±Æ·πÄ≈ª$;‚Ç¨‚Å∏b1Z∆ë$∆á·∏¢
```
[Try it online!](https://tio.run/##y0rNyan8/z/JMFj7UePOhzsWn5z@aOO6hzsbju5WsX7UtOZR444kw6hjE1WOtT/csei/zuH2o5Me7pwBlMl61DBHQddO4VHDXK7D7UCByP//o7miDWN1uKKNQIQxiDDUUYCIQGljBB9JCMY0ATONEEyYKBCBjTMFM5HUGqKaB@JxxQIA "Jelly ‚Äì Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~92 ... 85~~ 82 bytes
```
f=->l,*r{l==(0...l[0]).map{|x|l.count{|y|y>x}}?l:f[*r+(1..l.sum).map{|q|[q+1]+l}]}
```
[Try it online!](https://tio.run/##KypNqvz/P81W1y5HR6uoOsfWVsNAT08vJ9ogVlMvN7GguqaiJkcvOb80r6S6prKm0q6ittY@xyotWqtIW8MQqFCvuDQXqrKwJrpQ2zBWO6c2tvZ/gUJadLRhbCwXhKEDhjCukQ4YwrkwhjFCAVytMTITVRyZg6YMbqQJSPw/AA "Ruby ‚Äì Try It Online")
# Non-recursive version, 85 bytes
```
->l,*r{l,*r=r+(0..l.sum).map{|q|[q+1]+l}until(0...l[0]).map{|x|l.count{|y|y>x}}==l;l}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y5HR6uoGkTYFmlrGOjp5egVl@Zq6uUmFlTXFNZEF2obxmrn1JbmlWTmgKT1cqINYqHSFTU5esn5QKnqmsqaSruK2lpb2xzrnNr/BQpp0dGGsbFcEIYOGMK4RjpgCOfCGMYIBXC1xshMVHFkDpoyuJEmIPH/AA "Ruby ‚Äì Try It Online")
### How?
This explanation refers to the non-recursive version, which is functionally identical to the recursive one.
Sheer brute force:
```
->l,*r{
```
We must check all sequences, starting with the original: `r` is the list of sequence we haven't checked yet.
```
l,*r=r+(0..l.sum).map{|q|[q+1]+l}
```
This will be executed after each check: since the sequence is not symmetric (or not a Young diagram), we create a new list of sequence which can extend this one by adding one number at the beginning. The maximum possible value is the sum of the sequence + 1 (empirical evidence). The minimum is set to 0, this will generate a lot of non-Young diagrams, but those will be discarded by the check.
```
until(0...l[0]).map{|x|l.count{|y|y>x}}==l;
```
We've found the sequence if for any number `x` between 1 and the maximum value in `l`, the xth element of `l` is the number of elements of `l` that are greater or equal to `x`. If the first element of `l` is not the maximum, then the size of the sequence won't match (this will exclude all non-Young diagrams).
```
l}
```
Finally, return the sequence we have found.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 22 bytes
```
‚àûŒµLy√£}‚Ç¨` íI√Ö¬ø}.ŒîDƒÅŒ¥@√∏OQ
```
[Try it online!](https://tio.run/##ATMAzP9vc2FiaWX//@KIns61THnDo33igqxgypJJw4XCv30uzpRExIHOtEDDuE9R//9bMSwgMV0 "05AB1E ‚Äì Try It Online") or [Try all cases!](https://tio.run/##S0oszvifnFiiYKeQnJ@SqpeYlKpgY6Og7urvpv7/Uce8c1t9Kg8vrn3UtCbh1CTPw62H9tfqnZvicqTx3BaHwzv8A/8DFXJxlWdk5qQqFKUmpihk5nGl5HMpKOjnF5To5xcnJmWmQilkC2wUVMAK81L/RxvGckUbAbExEBvqKIC5EMoYzkMIQFkmYJYRnAUVAyKQMaZgFkKdIYpBYA4A)
```
‚àûŒµ   }          # for y in [1, 2, ...]
  L             #   take the range [1, ..., y]
   y√£           #   all y-tuples of these numbers
      ‚Ç¨`        # flatten the result by one level
         í   }   # filter; keep only those lists
         I√Ö¬ø    #   that end with the input
.Œî              # find the first list y that
  DƒÅŒ¥@√∏OQ       #   (is a symmetric Young diagram)
   ƒÅ            #   push range [1, ..., len(y)]
    Œ¥@          #   (<=) - table
      √∏O        #   sum the columns, the result is a list giving the count of numbers >= n for each n
  D     Q       #   is this equal to y?
```
[Answer]
# JavaScript, 110 bytes
```
f=(a,l,g=a=>{for(i=j=k=l;j||=k=--i&&l;b[l-i]||=!j*k)k-=a[--j]<i})=>g(c=b=[...a],b=[g(a,c)])|b==c+''?c:f(a,-~l)
```
```
f=(a,l,g=a=>{for(i=j=k=l;j||=k=--i&&l;b[l-i]||=!j*k)k-=a[--j]<i})=>g(c=b=[...a],b=[g(a,c)])|b==c+''?c:f(a,-~l)
console.log(JSON.stringify(f([1])));
console.log(JSON.stringify(f([2])));
console.log(JSON.stringify(f([3])));
console.log(JSON.stringify(f([1, 1])));
console.log(JSON.stringify(f([1, 2])));
console.log(JSON.stringify(f([1, 3])));
console.log(JSON.stringify(f([1, 2, 2])));
console.log(JSON.stringify(f([1, 2, 3])));
console.log(JSON.stringify(f([2, 2, 4])));
console.log(JSON.stringify(f([1, 2, 4])));
console.log(JSON.stringify(f([3, 4, 4])));
console.log(JSON.stringify(f([1, 4, 5])));
console.log(JSON.stringify(f([1, 1, 2, 4])));
console.log(JSON.stringify(f([1, 1, 2, 2])));
```
First, function `g` try to calculate transpose of some given input.
```
g=a=>{for(i=j=k=l;j||=k=--i&&l;b[l-i]||=!j*k)k-=a[--j]<i}
```
Although there is only a variable `a` before the fat arrow, it actually takes 3 parameters:
1. The length `l`
2. The input array `a`
3. The output array `b`
It returns the transpose via modify variable `b` in-place.
It assumes `a` have `l` elements (as if there are some `l`s padded at the end of `a`). And try to calculate `a`'s transpose. When `b` is given an non-empty array, `g` keeps values already in `b` as is, and only calculate the remaining values.
So, we can use this function to:
1. `g(a,c=b=[...a])` will try to append some values to input, so it at least `l` elements in it, and the largest value is `l`. And `c` is the calculate result.
2. After that, `g(c,b=[])`will transpose `c`.
3. Finally, we test `b==c+''`: It will be true only if `c` is identical to its transpose.
4. We return `c` if it is identical to its transpose, or reject `c` and try a larger `l`.
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/),31 25 bytes[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)
```
‚àß‚àò‚äí‚åæ/{‚äëùîΩ‚ä∏‚â°¬®‚ä∏/‚â†‚ä∏+‚ä∏‚àæ‚üúùï©¬®‚ÜëùîΩùï©}
```
[Try it here](https://mlochbaum.github.io/BQN/try.html#code=RiDihpAg4oin4oiY4oqS4oy+L3viipHwnZS94oq44omhwqjiirgv4omg4oq4K+KKuOKIvuKfnPCdlanCqOKGkfCdlL3wnZWpfQoKRsKo4p+oMeKfqeKAv+KfqDLin6nigL/in6gz4p+p4oC/4p+oMSwx4p+p4oC/4p+oMiwx4p+p4oC/4p+oMywx4p+p4oC/4p+oMiwyLDHin6nigL/in6gzLDIsMeKfqeKAv+KfqDQsMiwy4p+p4oC/4p+oNCwyLDHin6nigL/in6g0LDQsM+KfqeKAv+KfqDUsNCwx4p+p4oC/4p+oNCwyLDEsMeKfqeKAv+KfqDIsMiwxLDHin6k=).
How it works:
`‚àß‚àò‚äí‚åæ/` is a helper function for the transpose. It works by taking the [Indices](https://mlochbaum.github.io/BQN/doc/replicate.html#indices) `/`, then the [Occurrence Count](https://mlochbaum.github.io/BQN/doc/selfcmp.html#occurrence-count) `‚äí`, sorts `‚àß` the result, then finally because of the modifier Under `‚åæ` ‚Äî which conceptually means apply the function on the right, then the one on the left, then undo the one on the right‚Äîit takes the [inverse of Indices](https://mlochbaum.github.io/BQN/doc/replicate.html#inverse).
To visualize an example:
```
    / 5‚Äø4‚Äø1
0‚Äø0‚Äø0‚Äø0‚Äø0‚Äø1‚Äø1‚Äø1‚Äø1‚Äø2
    ‚äí 0‚Äø0‚Äø0‚Äø0‚Äø0‚Äø1‚Äø1‚Äø1‚Äø1‚Äø2
0‚Äø1‚Äø2‚Äø3‚Äø4‚Äø0‚Äø1‚Äø2‚Äø3‚Äø0
    ‚àß 0‚Äø1‚Äø2‚Äø3‚Äø4‚Äø0‚Äø1‚Äø2‚Äø3‚Äø0
0‚Äø0‚Äø0‚Äø1‚Äø1‚Äø2‚Äø2‚Äø3‚Äø3‚Äø4
    /‚Åº0‚Äø0‚Äø0‚Äø1‚Äø1‚Äø2‚Äø2‚Äø3‚Äø3‚Äø4
3‚Äø2‚Äø2‚Äø2‚Äø1
```
And then the main part:
```
{‚äëùîΩ‚ä∏‚â°¬®‚ä∏/‚â†‚ä∏+‚ä∏‚àæ‚üúùï©¬®‚ÜëùîΩùï©} # a 1-modifier where Transpose is ùîΩ and input is ùï©
                ‚ÜëùîΩùï©  # list the prefixes of transposed input
               ¬®     # for each prefix in the list:
        ‚â†‚ä∏+          #   add its length to itself
           ‚ä∏‚àæ‚üúùï©      #   and join to the input
      ‚ä∏/             # filter by:
  ùîΩ‚ä∏‚â°¬®               #   whether each element is equivalent to its transpose
 ‚äë                   # select first result
```
[Answer]
# [Python 3.8 (pre-release)](https://docs.python.org/3.8/), 142 bytes
```
lambda L:(Z:=[len([0for i in L if i>j])for j in range(L[0])])*0+min(K[:n]+L for n in range(1+len(Z))if(K:=[i+n for i in Z])[n:]==L[:len(Z)-n])
```
[Try it online!](https://tio.run/##VY/Bb4IwGMXP46/4PLXVugiiWUhq4sFdJNllJxmHqmXWYCGlbjPL/nbXggImJPS9/t77@pUXcyjU9KXU14x9XHN@2u45xBHeRCzJhcLJJCs0SJAKYpAZyMUxJc46Oktz9SlwnExSkpLhZHSSCq@TSKWjGBykOsgfuboNITLDa1suRwra6k1KEhWljMVJ1GBjlZKr0ZfIe/o@yFzAuz4LK5443QKDEy@x@OI5lao8G0yeqzKXBiMYLwARYrmdpTLM3ZFXldAGtoztrCq1VAZzisYLRLfEEz87URpYvb2utC60ndEQ5H5AyzwHIypTQemq9gPUppZ1tSzUYxYxNAyDrqG@HdhxFA0YohnK8C//I4giZuWOXBM/dU@3Py8JmmNAIbBq2qgpBfdZw6fgt14tPMf6bcoZ09YIm2DLdeiMQljrLhP0u2/2jWnb7vp@cwvMKTSFYT/ppveTYbNDQz4kZ/d8N9PvLxH0l324nPf3qJF/ "Python 3.8 (pre-release) ‚Äì Try It Online")
Ungolfed:
```
def f(L):
  Z = [0]*L[0]
  for i in L:
    Z[:i] = [j+1 for j in Z[:i]]
  # Z is now transpose of L
  for n in range(1+len(Z)):
    K = [i+n for i in Z]
    # K is the start of the transpose of (L with n elements prepended)
    if K[n:]==L[:len(Z)-n]: # the overlapping parts must be equal
      return K[:n]+L
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 21 bytes
```
~a‚ÇÅ.R‚Å∞l‚ü¶‚ÇÖ{{<.‚àßR‚Å∞‚àã}·∂ú}·µê
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/vy7xUVOjXtCjxg05j@Yve9TUWl1to/eoYzlI5FFHd@3DbXNqH26d8P9/tKmOiY5h7P8IAA "Brachylog ‚Äì Try It Online")
My first Brachylog program, so it can probably be improved a lot.
## Explanation
```
~a‚ÇÅ.R‚Å∞l‚ü¶‚ÇÖ{{<.‚àßR‚Å∞‚àã}·∂ú}·µê
                       The input
~a‚ÇÅ                    is a suffix of
   .                   the output,
    R‚Å∞                 aka R‚Å∞.
      l                The output's length,
       ‚ü¶‚ÇÖ              range from 0 to that-1,
         {         }·µê  map:
          {      }·∂ú      count all possible outputs of this predicate:
                           The number
           <               is less than
            .              the output
             ‚àß             and
              R‚Å∞           R‚Å∞
                ‚àã          contains
                           the output.
                       this has to be equal to the output.
```
[Answer]
# JavaScript (ES6), 117 bytes
```
f=(a,n)=>(g=(i,a,n)=>n?i>n?0:g(i,[i,...a],n-i)||g(i+1,a,n):i--?a.map(v=>t-=v>i,t=a[i])|t?0:g(i,a):a)(1,a,n)||f(a,-~n)
```
[Try it online!](https://tio.run/##dZHRboMgFIbv9xRcQnagE20vTLAPYrwgXTUsHTar8Yrs1R2KpJ1HjCbkz8f3H@FLj/px@TH3gdv@8zpNraIaLFMV7RQ1ENb2bPz3UXY@qQ0IIXQDlhvmnI/eswUrDednLb71nY6qGrgaKwOD0rVpmBvW3ZqVmtGwwbnWd/Ffy6ZLbx/97SpufUdbWmcNiQ9j5HAgPnnbMBIxEohEWI6wHMj8IjIDEnuf5BKiakTKPSxHWBGqE86oXeEjkGIJU/INnyfIVdL8GyOG@/Cr9gQkTFKk/fN/IX@xd8hBhf3H2JKaf7mIp1@mr2YDn16Pcc6nPw "JavaScript (Node.js) ‚Äì Try It Online")
### How?
Starting with \$n=0\$, we prepend each non-increasing integer partition of \$n\$ to the input list and test whether one of the resulting lists is a symmetric Young diagram. We recursively increment \$n\$ until a solution is found.
For instance, the test case `[5, 4, 1]` is solved with \$n=16=6+5+5\$, leading to `[6, 5, 5, 5, 4, 1]`.
### Faster version (120 bytes)
This version will never generate a partition with a term less than the leading term of the input list. This allows it to solve `[9, 2]` (suggested by Wheat Wizard) almost instantly.
[Try it online!](https://tio.run/##LY3BCsMgEER/pcddqpL2VsHkQ8TDkkbZkmpoxJPk162kPQwMj3nMiwrt84e3LGN6Lq15AyQimhGCARa/HifuGXToxLJQSpETUTLW2tH1ds40SzmRetMGxYxZmjKyyIYsO6z5bxNqQiA7uNOp1fc7eURsc4p7Whe1pgAe7ENc7g6xfQE "JavaScript (Node.js) ‚Äì Try It Online")
### Commented
```
f = (a, n) => (       // f = main function taking the input list a[]
  g = (i, a, n) =>    // g = helper function computing the partitions
                      //     and looking for a symmetric Young diagram
    n ?               // if n is not 0:
      i > n ?         //   if i is greater than n:
        0             //     invalid partition: abort
      :               //   else:
        g(            //     first recursive call:
          i,          //       pass i unchanged
          [i, ...a],  //       prepend i to a[]
          n - i       //       subtract i from n
        ) ||          //     end of recursive call
        g(            //     second recursive call:
          i + 1,      //       increment i
          a,          //       pass a[] unchanged
          n           //       pass n unchanged
        )             //     end of recursive call
    :                 // else (n = 0 or undefined):
      i-- ?           //   decrement i; if it was not 0:
        a.map(v =>    //     for each value v in a[]:
          t -= v > i, //       decrement t if v is greater than i
          t = a[i]    //       starting with t = a[i]
        ) | t ?       //     end of map(); if t is not 0:
          0           //       this is not a symmetric Young diagram
        :             //     else:
          g(i, a)     //       process recursive calls until i = 0
      :               //   else:
        a             //     success: return a[]
)(1, a, n)            // initial call to g
|| f(a, -~n)          // if no solution was found, try again with n + 1
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~43~~ 35 bytes
```
Ôº∑Ôº≥‚äûœÖÔº¨Œπ¬ßŒ¶Ôº•‚äï‚åàœÖ‚Å∫Ôº•Œπ‚Å∫ŒπÔº¨Œ¶œÖ‚Ä∫ŒΩŒºœÖ‚¨§Œπ‚ÅºŒªÔº¨Œ¶Œπ‚Ä∫ŒΩŒº‚Å∞
```
[Try it online!](https://tio.run/##bY7BCsIwDIbve4oeU@jAu6cdVAYKA5@gbGENpHV27dzb13YOD@J/CH/I/yXpjfb9Q3NKL0OMAlo3xXAPntwIUoouzgaiEld0YzBAUh6rLg8DNKF1A65wJg7o4aanzPYeLbqAQ@5XstFClFKJjuO8JWj39N244/nExaMu1ilhZZESG9wwl/zpGTXPwL8k/SEzdcifplQXVZ9SpXrhNw "Charcoal ‚Äì Try It Online") Link is to verbose version of code. I/O is as a Young Diagram using `-`s as the fill character. Explanation:
```
Ôº∑Ôº≥‚äûœÖÔº¨Œπ
```
Input the diagram.
```
Ôº•‚äï‚åàœÖ
```
For each possible number of rows from `0` to the length of the first row (inclusive)...
```
‚Å∫Ôº•Œπ‚Å∫ŒπÔº¨Œ¶œÖ‚Ä∫ŒΩŒºœÖ
```
... calculate the transpose of that number of columns, concatenating with the original input.
```
¬ßŒ¶...‚¨§Œπ‚ÅºŒªÔº¨Œ¶Œπ‚Ä∫ŒΩŒº‚Å∞
```
Print the first symmetric result.
Example: At each stage, an `i`-by-`i` square is prefixed to the original input (marked by `#` signs) and then extended by transposition (marked by `=` signs). The first symmetric result is then the one with `3` prefixed rows.
```
                                        #####===
                                ####=== #####==
                        ###===  ####==  #####==
                ##===   ###==   ####==  #####==
        #===    ##==    ###==   ####==  #####=
-----   =----   ==---   ===--   ====-   =====
----    =---    ==--    ===-    ====    ====
-       =       =       =       =       =
0       1       2       3       4       5
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~87~~ ~~86~~ ~~76~~ 72 bytes
```
l&@For[i=0,t@@(l=Join[l=#;i+t@i++,#])!=l,]&
t=Tr@UnitStep[l-#]&~Array~#&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7P0fNwS2/KDrT1kCnxMFBI8fWKz8zLzrHVtk6U7vEIVNbW0c5VlPRNkcnVo2rxDakyCE0L7MkuCS1IDpHVzlWrc6xqCixsk5Z7X9AUWZeSbSyrl2aA0g8ODkxr66aq9qwVoer2ghEGIMIQx2IAIQyhvHgfCjDBMgwgjGgIiY6YBNMgQy4GkMkAyBMS6A@rtr/AA "Wolfram Language (Mathematica) ‚Äì Try It Online")
The helper function `t` returns the first `#` rows of the transpose of the Young diagram of `l`.
```
main function:
   For[i=0,                             ,]  start from i=0 (#extra rows)
                      l=#;  t@i             first i rows of transposed input
                          i+                shift right by i
                 Join[           ,#]        prepend to input
           t@@(l=                   )!=l    transpose equal to itself?
l&@                                           (yes): return
                              i++             (no) : increment i and retry
t:
Tr@UnitStep[l-#]                                count entries of l >= i
                &~Array~#                       for i=1..first argument
```
[Answer]
# [R](https://www.r-project.org/), ~~116~~ 106 bytes
```
function(x,u=function(a,b)colSums(outer(b,1:a,`>=`)),y=x){while(any(y-u(max(y),y)))y=c(u(F<-F+1,x)+F,x);y}
```
[Try it online!](https://tio.run/##TY/BDoIwDIZfpw3lMMCLOo@8gA8gY85IMsYCLG4xPvucEQiXft/fNk06xr4zNzsqq8ydx4czcu4GA54c34KgFuWgr66fYHCzGqEldhTUXHiDSIF7fL@enVYgTICQO@iFh5AmiBi4BAf1Oa8zRh6zOpVT@EQtrNUBdDfNwKigkmQiw4Tij3JNW16kSlKssnQqKn9ySLLtsN2BpEi7XzF@AQ "R ‚Äì Try It Online")
Uses strategy copied from [Neil's answer](https://codegolf.stackexchange.com/a/235875/95126) - upvote that one!
]