easy bfs solution
IntuitionDo bfs take all nodes in a vector and sort that vector compare how many swaps are required and return it.Complexity

Time complexity:
O(nlogn)


Space
# Intuition
Do bfs take all nodes in a vector and sort that vector compare how many swaps are required and return it.



# Complexity
- Time complexity:
O(nlogn)

- Space complexity:
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 minop(vector<int>& arr){
        vector<int> ans(begin(arr),end(arr));
        sort(begin(arr),end(arr));
        unordered_map<int,int> mp;
        int n=arr.size();
        for(int i=0;i<n;i++){
            mp[arr[i]]=i;
        }
        int swaps=0;
        for(int i=0;i<n;i++){
            if(arr[i]==ans[i]) continue;
            int idx=mp[ans[i]];
            mp[arr[i]]=idx;
            mp[ans[i]]=i;
            swap(arr[i],arr[idx]);
            swaps++;

        }
        return swaps;
    }
    int minimumOperations(TreeNode* root) {
        queue<TreeNode*> q;
        q.push(root);
        int result=0;
        while(!q.empty()){
            int n=q.size();
            vector<int> vec;
            while(n--){
                TreeNode* curr=q.front();
                q.pop();
                vec.push_back(curr->val);
                if(curr->left){
                    q.push(curr->left);
                }
                 if(curr->right){
                    q.push(curr->right);
                }

            }
            result+=minop(vec);
            
        }
        return result;
    }
};
```
['C++']