GFG-POTD | Remove Half Nodes using Java | 20 July 2024 | Tree | Data Structures | Practice |

preview_player
Показать описание
Geeks-for-Geeks | Practice Problem
20 July 2024
Problem : Remove Half Nodes using Java
Level : Easy
Language : Java
Topics Tag : Tree | Data Structures | Algorithms

____________________________________________________

Recent GFG Problem Solution :

🧩 1605. Find Valid Matrix Given Row and Column Sums

🧩 Longest alternating subsequences

⬇️ You may also visit my another playlists :

👉 LeetCode Problems :

👉 Code360 by coding ninja's mcq solution :

👉 Geeks-for-Geeks :

--------------------------------------

Stay connected with me on social media for more updates and behind-the-scenes content !

You can find me on 🔍:

📱 Instagram Profile :

🌐 LinkedIn Profile :

-----------------------------------------------------

➡️ Problem Statement as follows :

You are given a binary tree and you need to remove all the half nodes (which have only one child). Return the root node of the modified tree after removing all the half-nodes.

Note: The output will be judged by the inorder traversal of the resultant tree, inside the driver code.

Examples:

Input: tree =
5
/ \
7 8
/
2

Output: 2 5 8

Explanation: In the above tree, the node 7 has only single chile. After removing the node the tree becomes 2 less than -5- greater than 8. Hence, the answer is 2 5 8 & it is in inorder traversal.
Input: tree =
2
/ \
7 5

Output: 7 2 5

Explanation: Here there are no nodes which has only one child. So the tree remains same.

Expected Time Complexity: O(n)
Expected Auxiliary Space: O(height of the binary tree)

---------------------------------------------

📚 Check out other problems! 🔍:

🧩 1. Partitions with Given Difference | Java | GeekforGeeks | Practice Problem


🧩 2. K-Palindrom | Java | GeeksforGeeks | Practice Problems

🧩 3. [ Part-02 ] Maximum Score Words Formed by Letters - Leetcode

🧩4. Mobile Numeric Keypad :

🧩 5. Boring Factorial ( Coding Ninjas ) :

🧩 6. Coverage of all Zeros in a binary matrix

🧩 7. Make Binary Tree From Linked List :

--------------------------------------------------

#gfgproblemoftheday
#gfgsolutions
#gfgproblems
#RemoveHalfNodes
#RemoveHalfNodesusingjava
#RemoveHalfNodesjavasoluton
#RemoveHalfNodesproblemoftheday
#RemoveHalfNodesproblemsolution
#RemoveHalfNodesgfgsolution
#RemoveHalfNodesgfgsolution
#RemoveHalfNodesusingjavaproblemoftheday
Рекомендации по теме
join shbcf.ru