Error
|
|
---|---|
@Ibrahim Nash | 6379 |
@blackshadows | 6329 |
@mb1973 | 5358 |
@Quandray | 5231 |
@akhayrutdinov | 5111 |
@saiujwal13083 | 4510 |
@sanjay05 | 3762 |
@marius_valentin_dragoi | 3522 |
@sushant_a | 3459 |
@verma_ji | 3357 |
@KshamaGupta | 3318 |
Complete Leaderboard | |
|
|
@ritiksethi21 | 1050 |
@aroranayan999 | 807 |
@RizulBansal | 685 |
@ashishtrehan002 | 538 |
@hemantgarg923 | 528 |
@simrangoyal | 526 |
@ronaldo77 | 520 |
@thanosagain | 505 |
@anishrajan | 505 |
@ssparteek470 | 495 |
@rahul2312 | 491 |
Complete Leaderboard |
Given a AVL tree and N values to be deleted from the tree. Write a function to delete a given value from the tree.
Example 1: Tree = 4 / \ 2 6 / \ / \ 1 3 5 7 N = 4 Values to be deleted = {4,1,3,6} Input: Value to be deleted = 4 Output: 5 / \ 2 6 / \ \ 1 3 7 Input: Value to be deleted = 1 Output: 5 / \ 2 6 \ \ 3 7 Input: Value to be deleted = 3 Output: 5 / \ 2 6 \ 7 Input: Value to be deleted = 6 Output: 5 / \ 2 7
Your Task:
You dont need to read input or print anything. Complete the function delelteNode() which takes the root of the tree and the value of the node to be deleted as input parameters and returns the root of the modified tree.
Note: The tree will be checked after each deletion.
If it violates the properties of balanced BST, an error message will be printed followed by the inorder traversal of the tree at that moment.
If instead all deletion are successful, inorder traversal of tree will be printed.
If every single node is deleted from tree, 'null' will be printed.
Expected Time Complexity: O(height of tree)
Expected Auxiliary Space: O(height of tree)
Constraints:
1 ≤ N ≤ 500
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes