Encoding February'20 's Problem Doubt

Can anyone please help with this problem, there is no editorial for it.

I think, we can decide some colours which are to be arranged in the first column, and then each of the selected colour should be present in the last column at least once in any order , and the rest of the (n) X (n-2) matrix can have any distribution with these decided colours, because now,no matter wherever we draw a vertical line , number of distinct colours in the two parts will be same…I couldn’t implement it.
Can anyone please let me know, if this approach is correct and how can i implement it.
Or suggest some better approach…

@carre @everule1