Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions Lecture-070/4_Kth_Largest_In_BST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
using namespace std;

int kthLargest(Node* root, int &index, int K) {

if(root == NULL) {
return -1;
}

// Reverse Inorder Traversal
int right = kthLargest(root->right, index, K);
if(right != -1) {
return right;
}

index++;
if(index == K) {
return root->data;
}

return kthLargest(root->left, index, K);
}

int main() {
Expand All @@ -24,4 +39,4 @@ int main() {

cout << "Required answer = " << ans << endl;
return 0;
}
}