Efficient Approach to Order Vectors?

33 Views Asked by At

given $n$ binary victors which may include $\$$ sign like this: $101\$0111$

What's the most efficient algorithm to order those vectors in $nxn$ matrix such that in the main diagonal there is no $\$$ signs? (In case it's not possible then output "Not possible"?

There is a trivial solution in $O(n!)$ by checking all possible options to order them and validating each option. Is there a more efficient approach maybe in polynomial time?