Python3 | Easy Solution
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#         se
# 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        queue = deque([root])\n        ans = 0\n        while len(queue)!=0:\n            levelNode = []\n            for k in range(len(queue)):\n                nowNode = queue.popleft()\n                levelNode.append(nowNode.val)\n                if nowNode.left!=None:\n                    queue.append(nowNode.left)\n                if nowNode.right!=None:\n                    queue.append(nowNode.right)\n            \n            levelNodeSort = sorted(levelNode)\n            posDict = defaultdict(int)\n            for i in range(len(levelNode)):\n                posDict[levelNode[i]] = i\n            for i in range(len(levelNode)):\n                if(levelNode[i]!=levelNodeSort[i]):\n                    replace = posDict[levelNodeSort[i]]\n                    levelNode[replace] = levelNode[i]\n                    posDict[levelNode[i]] = replace\n                    levelNode[i] = levelNodeSort[i]\n                    ans+=1\n\n        return ans\n                    \n                \n        \n```
['Python3']