Current streak:
0 days
Longest streak:
11 days
Less
More
void findKthLargest(Node* root, int k, int& count, int& kthLargest) {
if (root == NULL) {
return;
}
findKthLargest(root->right, k, count, kthLargest);
count++;
if (count == k) {
kthLargest = root->data;
return;
}
findKthLargest(root->left, k, count, kthLargest);
}
int KthLargest(Node* root, int k) {
int count = 0;
int kthLargest = -1;
findKthLargest(root, k, count, kthLargest);
return kthLargest;
}