Easy solution using BFS and Hashing!! JAVA
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->Level order --> BFS!!


# Approach
<!-- Describe your approach to solving the problem. -->Apply BFS, store the values of each level in an array, compare with a sorted version of the array and make changes and swaps accordingly with the help of a hashmap!!

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

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

# Code
```java []
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public int minimumOperations(TreeNode root) {
        Queue<TreeNode> q = new LinkedList<>();
        q.offer(root);
        int swaps = 0;
        while(!q.isEmpty()){
            int currLvlSize = q.size();
            int[] lvl = new int[currLvlSize];
            for(int i = 0; i<currLvlSize; i++){
                TreeNode node = q.poll();
                lvl[i] = node.val;
                if(node.left != null){
                    q.offer(node.left);
                }
                if(node.right != null){
                    q.offer(node.right);
                }

            }
            swaps += minSwaps(lvl);
        }
        return swaps;
    }
    public int minSwaps(int[] arr){
        int swap = 0;
        int[] sorted = new int[arr.length];
        for(int i = 0; i<arr.length; i++){
            sorted[i] = arr[i];
        }
        Arrays.sort(sorted);
        HashMap<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i<arr.length; i++){
            map.put(arr[i], i);
        }
        for(int i = 0;i<arr.length; i++){
            if(arr[i] != sorted[i]){
                int currPos = map.get(sorted[i]);
                map.put(arr[i],currPos);
                arr[currPos] = arr[i];
                swap++;
            }
        }
        return swap;
    }
}
```
['Java']