BFS AND SORTING 
IntuitionIN THIS PROBLEM WE CAN EASILY TAKE THIS INTUITION THAT FIRST WE NEED TO TAKE THE BFS
IN EACH LEVEL YOU WILL GET AN ARRAY THAT ARRAY HAS TO BE SORTED.Co
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
IN THIS PROBLEM WE CAN EASILY TAKE THIS INTUITION THAT FIRST WE NEED TO TAKE THE BFS
IN EACH LEVEL YOU WILL GET AN ARRAY THAT ARRAY HAS TO BE SORTED.
<!-- # Approach -->
<!-- Describe your approach to solving the problem. -->

<!-- # Complexity
- Time complexity: -->
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

<!-- - Space complexity: -->
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    int sortfn(vector<int>& arr){
        vector<int> v=arr;
        sort(v.begin(),v.end());
        map<int,int> mpp;
        for(int i=0;i<arr.size();i++){
            mpp[arr[i]]=i;
        }
        int total=0;
        for(int i=0;i<arr.size();i++){
            if(arr[i]!=v[i]){
                total++;
                int curr=mpp[v[i]];
                mpp[arr[i]]=curr;
                swap(arr[i],arr[curr]);
            }
            
        }
        return total;
        
    }
    int minimumOperations(TreeNode* root) {
        queue<TreeNode*> bfsq;
        bfsq.push(root);
        int count=0;
        
        while(!bfsq.empty()){
            vector<int> arr;
            int n=bfsq.size();
            for(int i=0;i<n;i++){
                TreeNode* currnode=bfsq.front();
                bfsq.pop();
                if(currnode->left) bfsq.push(currnode->left);
                if(currnode->right) bfsq.push(currnode->right);
                arr.push_back(currnode->val);
            }
            count+=sortfn(arr);
        }
        return count;
        
        
    }
};
```
['Tree', 'Breadth-First Search', 'Binary Tree', 'C++']