Algorithm required, any language, or pseudo language
TLDR: have an array of arrays, you need to sort each inner array in way that matches fallowing requirements:
- Input array contains set of arrays.
- Each inner array contains unique elements.
- Each inner array may have different length and different values.
- Output array must contain exact same values.
- Output inner array must have unique values on same key.
- If there is no solution, wildcard ie.: null are allowed.
- Wildcards can be duplicated on same key.
- Solution should have as few wildcards as possible.
- Algorithm should be able to handle array up to 30x30 in less than 180 s. so avoid bruteforcing.
my best solution so far is to get all elements, define maximum size of array, (so in input array is 2x3 output must be 3x3) then loop trough all elements and fill array with first one and fallow until all elements are used. I have found that key here is order of elements you fill.
[X, Y] solved by [X,Y] [X, Y] . [Y,X] [X, Y, Z] solved by [X,Y,Z] [X, Y, Z] . [Z,X,Y] [X, Y, Z] . [Y,Z,X] [X, Y, Z] solved by [X,Y,Z] [X, A, Z] . [Z,X,A] [X, Y, A] . [Y,A,X] [X, Y] solved by [X,Y,_] [X, Y] . [_,X,Y] [X, Y] . [Y,_,X]
This may looks easy but this is not