All Tree Important Interview Problems in One Place
This very basic tree traversal problem.\n\nYou can also solve or revise other Interview Important tree problems from my post - https://leetcode.com/discuss/stud
This very basic tree traversal problem.\n\nYou can also solve or revise other ***Interview Important*** tree problems from my post - https://leetcode.com/discuss/study-guide/937307/iterative-recursive-dfs-bfs-tree-traversal-in-pre-post-levelorder-views\n\n\n```\nclass Solution {\n    public List<List<Integer>> levelOrder(TreeNode root) {\n        List<List<Integer>> result = new ArrayList();\n        if(root == null)\n            return result;\n        \n        Queue<TreeNode> q = new LinkedList();\n        q.add(root);\n        while(q.size() > 0) {\n            int size = q.size();\n            List<Integer> level = new ArrayList();\n            while(size-- > 0) {\n                root = q.poll();\n                level.add(root.val);\n                if(root.left != null)\n                    q.add(root.left);\n                if(root.right != null)\n                    q.add(root.right);\n            }\n            result.add(level);\n        }\n        \n        return result;\n    }\n}\n```\n\nIf you like **upvote**.
['Tree', 'Depth-First Search', 'Breadth-First Search']