Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
The score function is cyclic, so we can always set <code>perm[0] = 0</code> for the smallest lexical order.
It’s similar to the Traveling Salesman Problem. Use Dynamic Programming.
Use a bitmask to track which elements have been assigned to <code>perm</code>.