Meta Interview Question

NDA signed. But the question involved matrix calculations and required backtracking. Best solution was n!