✅ 🔥 BEATS 83% 🔥|| JAVA || BFS 
IntuitionThe problem requires finding the minimum number of operations to make each level of a binary tree sorted in ascending order. The intuition is to perfor
# Intuition
*The problem requires finding the minimum number of operations to make each level of a binary tree sorted in ascending order. The intuition is to perform a level-order traversal (BFS) and for each level, calculate the minimum number of swaps needed to sort the values.*

# Approach
1. Perform a level-order traversal using a queue.
2. For each level:
  Collect the node values in a list.
  Calculate the minimum number of swaps needed to sort this list.
  Add this count to the total operations.
3. To calculate the minimum swaps:
Create a sorted copy of the level's list.
Use a map to track the original indices of values.
Compare the original list with the sorted list and swap as needed.

# Complexity
- Time complexity:
O(nlogn)

- Space complexity:
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 GetSwap(int[] arr){
        int swap=0;
        int[] target=arr.clone();
        Arrays.sort(target);

        Map<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] != target[i]){
                swap++;

                int currPos=map.get(target[i]);
                map.put(arr[i],currPos);
                arr[currPos]=arr[i];
            }
        }
        return swap;
    }
    public int minimumOperations(TreeNode root) {
        Queue<TreeNode> queue=new LinkedList<>();
        queue.offer(root);
        int totalSwaps=0;

        while(!queue.isEmpty()){
            int size=queue.size();
            int[] arr=new int[size];

            for(int i=0;i<size;i++){
                TreeNode node=queue.poll();
                arr[i]=node.val;
                if(node.left != null){
                    queue.offer(node.left);
                }
                if(node.right != null){
                    queue.offer(node.right);
                }
            }
            totalSwaps+=GetSwap(arr);
        }
        return totalSwaps;
    }
}
```
['Hash Table', 'Breadth-First Search', 'Binary Tree', 'Java']