A notes app stores tag ids in a binary search tree with unique values. When a user deletes a tag, its node must be removed while keeping the search tree rule.
Write removeTag(root, tag) that removes the node with value tag and returns the new root. Use exactly these rules so the result is unique:
tag isn't in the tree, return the tree unchanged.Input: root = [50,30,70,20,40,60,80], tag = 30 Output: [50,40,70,20,null,60,80]
30 has two children. Its successor is 40, which is copied up; then the old 40 leaf is removed.
Input: root = [50,30,70,20], tag = 30 Output: [50,20,70]
30 has one child, 20, which takes its place.
0 <= number of tags <= 10000Trees are written level by level, like [1, 2, 3, null, 4], where null is a missing child. Your function works with TreeNode objects, each with val, left, and right.
Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #340 Remove a Tag From the Tag Tree. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.