NOT Very Short But Easy And Simple C++ Solution Using Level Order Traversal ; Beats 92.13%
\n# Code\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode(
\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int exe(vector<int>&nums)\n\t{\n\t    vector<pair<int,int>> v;\n\t    int n=nums.size();\n\t    for(int i=0;i<n;i++)\n\t    {\n\t        v.push_back({nums[i],i});\n\t    }\n\t    sort(v.begin(),v.end());\n\t    int cnt=0;\n\t    for(int i=0;i<n;i++)\n\t    {\n\t        if(v[i].second==i) continue;\n\t        else {\n\t            cnt++;\n\t            swap(v[i],v[v[i].second]);\n\t            i--;\n\t        }\n\t    }\n\t    return cnt;\n\t}\n    int minimumOperations(TreeNode* root) {\n     int ans=0;\n     queue<TreeNode*> q;\n       q.push(root);\n        if(root==NULL)\n            return 0;\n        \n        while(1){\n            int size=q.size();\n            \n            if(size==0)\n                break;\n         vector<int> res;\n            while(size>0){\n                TreeNode* temp = q.front();\n          q.pop();\n                res.push_back(temp->val);\n                if(temp->left != NULL)\n                    q.push(temp->left);\n                \n                if(temp->right!= NULL)\n                    q.push(temp->right);\n                \n                size--;\n            }\n     ans+=exe(res);\n        }\n     return ans;   \n    }\n};\n```
['Breadth-First Search', 'Binary Tree', 'C++']