Sum of Kth Largest Element in Binary Search Tree

Given a binary search tree with positive integers, find the sum of k largest elements of the BST. (given k <= number of elements in BST) for eg: 5 / \ / \ 3 7 / \ / \ 2 4 6 8 k = 3 Sum = 6 + 7 + 8 = 21 Output: 21 Here is sample Node.java (No need to upload this) public class Node { public int nodeValue; public Node lChild; public Node rChild; }

Answer


No comments:

Post a Comment