Approach :- Simple BFS | C++ | Queue
\nRuntime: 16 ms, faster than 93.49% of C++ online submissions for Delete Nodes And Return Forest.\nMemory Usage: 25.4 MB, less than 59.82% of C++ online submis
```\nRuntime: 16 ms, faster than 93.49% of C++ online submissions for Delete Nodes And Return Forest.\nMemory Usage: 25.4 MB, less than 59.82% of C++ online submissions for Delete Nodes And Return\n```\n# \n## Approach :- Simple BFS\n# \n1) First Push root into `queue`.\n2) Push it\'s child into the `queue` if exists.\n3) Now, we have two options :-\n    a) We can first take `front` and then go to it\'s children if exists.\n   b) We can first go to it\'s children if exists and then take `front`.\n4) So here, We\'ll first check if according to problem, we need to `destruct/remove` it\'s children. We\'ll do that first. If any non-destruct child left, we\'ll take into account as in our `result.`\n```\n#define data val\nclass Solution {\npublic:\n\tvector<TreeNode*> delNodes(TreeNode* root, vector<int>& to_delete) {\n\t\tif (!root)\n\t\t\treturn {};\n\n\t\tunordered_set<int> toDelNodes;\n\t\tvector<TreeNode*> result;\n\t\tfor (auto it : to_delete) {\n\t\t\ttoDelNodes.insert(it);\n\t\t}\n\n\t\tif (toDelNodes.find(root->data) == toDelNodes.end()) {\n\t\t\tresult.push_back(root);\n\t\t}\n\n\t\tqueue<TreeNode*> pendingNodes;\n        pendingNodes.push(root);\n        \n\t\twhile(!pendingNodes.empty()){\n\t\t\tauto front = pendingNodes.front();\n\t\t\tpendingNodes.pop();\n\n\t\t\tif(front->left) pendingNodes.push(front->left);\n\t\t\tif(front->right) pendingNodes.push(front->right);\n\n\t\t\tif(front->left && toDelNodes.count(front->left->data)){\n\t\t\t\tfront->left = NULL;\n\t\t\t}\n\t\t\tif(front->right && toDelNodes.count(front->right->data)){\n\t\t\t\tfront->right = NULL;\n\t\t\t}\n\n\t\t\tif(toDelNodes.count(front->data)){\n\t\t\t\tif(front->left) result.push_back(front->left);\n\t\t\t\tif(front->right) result.push_back(front->right);\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n};\n```\n**Kindly UpVote this article, if it helps you a bit.**
['Breadth-First Search', 'C']