[Python3] BFS + Cyclic Sort - Simple Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(NlogN)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(N)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n# Definition for a binary tree node.\n# class TreeNode:\n#     def __init__(self, val=0, left=None, right=None):\n#         self.val = val\n#         self.left = left\n#         self.right = right\nclass Solution:\n    def minimumOperations(self, root: Optional[TreeNode]) -> int:\n        def min_swap(arr: List[int]) -> int:\n            pos = {m:j for j,m in enumerate(sorted(arr))}  \n            visited = [0 for _ in range(len(arr))]\n            num_swap = 0\n            for i in range(n):\n                cnt = 0\n                while not visited[i] and i != pos[arr[i]]:\n                    visited[i], i = 1, pos[arr[i]]\n                    cnt += 1\n                num_swap += max(0, cnt - 1)\n            return num_swap\n\n        dq, res = collections.deque([root]), 0\n        while dq:\n            vals = []\n            n = len(dq)\n            for _ in range(n):\n                node = dq.popleft()\n                vals.append(node.val)\n                if node.left: dq.append(node.left)\n                if node.right: dq.append(node.right)\n            res += min_swap(vals)\n        return res\n```
['Breadth-First Search', 'Sorting', 'Python3']