Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Wednesday, August 9, 2017

Delete Nodes Greater than K


Explanation:
check if root's data is greater than k then return its left node.

Code:

      public Node deleteNode(Node root,int x)
             {
             if(root==null)
             return null;
             root.left=deleteNode(root.left,x);
             root.right=deleteNode(root.right,x);
             if(root.data>=x)
             {
                 return root.left;
             }
             return root;
             }

Stats

468319