Problem 2471 · Medium

Minimum Number of Operations to Sort a Binary Tree by Level

Sorting a level by swaps needs one swap per element outside each permutation cycle, so each cycle of length k costs k minus one.

Open the interactive visualisation