usnig level order + min swaps
Intuitionlevel order traversal + min swaps to get sorted arrayApproachfind the elements in each level and store it in a vector, and then apply min swaps to get
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
level order traversal + min swaps to get sorted array

# Approach
<!-- Describe your approach to solving the problem. -->
find the elements in each level and store it in a vector, and then apply min swaps to get that level sorted algo;
for level order use queue, 
for min swaps :
    ->store the elements and their indexes in a vector< pair >
->sort this vector< pair> then you will get some idea on the swapped indexes
->now for each swapping we get a cyclic structure : if the cycle consists of n nodes then n-1 swaps will be happining.


# 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 minimumOperations(TreeNode* root) {
        queue<TreeNode*> q;
        q.push(root);
        int ans=0;
        while(!q.empty()){
            int size=q.size();
            vector<int> level;
            for(int i=0;i<size;i++){
                TreeNode* node=q.front();
                q.pop();
                level.push_back(node->val);
                if(node->left!=NULL){
                    q.push(node->left);
                }
                if(node->right!=NULL){
                    q.push(node->right);
                }
            }
            vector<pair<int,int>> v;
            vector<int>vis(level.size(),0);
            for(int i=0;i<level.size();i++){
                v.push_back({level[i],i});
            }
            sort(v.begin(),v.end());
            for(int i=0;i<level.size();i++){
                if(vis[i]==1||v[i].second==i){
                    continue;
                }
                int cycle=0;
                int j=i;
                while(vis[j]==0){
                    vis[j]=1;
                    j=v[j].second;
                    cycle++;
                }
                if(cycle>0){
                    ans+=cycle-1;
                }
            }
        }
        return ans;
    }
};
```
['Breadth-First Search', 'Queue', 'C++']