JAVA | Level order traversal
\npublic int minimumOperations(TreeNode root) {\n        Queue<TreeNode> q = new LinkedList<>();\n        q.offer(root);\n        int res = 0;\n        while(!q
```\npublic int minimumOperations(TreeNode root) {\n        Queue<TreeNode> q = new LinkedList<>();\n        q.offer(root);\n        int res = 0;\n        while(!q.isEmpty()){\n            ArrayList<Integer> list = new ArrayList<>();\n            int count = q.size();\n            for(int i = 0; i < count; i++){\n                TreeNode cur = q.remove();\n                // if(cur.left > cur.right) res++;\n                list.add(cur.val);\n                if(cur.left != null) q.offer(cur.left);\n                if(cur.right != null) q.offer(cur.right);\n            }\n            res += minSwaps(list, list.size());\n        }\n        return res;\n    }\n    \n    public int minSwaps(ArrayList<Integer> list, int N){\n        int ans = 0;\n        ArrayList<Integer> temp = new ArrayList<>(list);\n \n\n        HashMap<Integer, Integer> h\n            = new HashMap<Integer, Integer>();\n \n        Collections.sort(temp);\n        for (int i = 0; i < N; i++){\n            h.put(list.get(i), i);\n        }\n        for (int i = 0; i < N; i++){\n \n            if (list.get(i) != temp.get(i))\n            {\n                ans++;\n                int init = list.get(i);\n \n\n                Collections.swap(list, i, h.get(temp.get(i)));\n \n                h.put(init, h.get(temp.get(i)));\n                h.put(temp.get(i), i);\n            }\n        }\n        return ans;\n    }\n```
['Breadth-First Search', 'Sorting', 'Java']