Problem 3644 · Medium

Maximum K to Sort a Permutation

Find the largest k for which a permutation can be sorted using only swaps of pairs whose bitwise AND equals exactly k. A permutation that is already sorted gives 0.

Open the interactive visualisation