-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Problem: kth max & min in BST #62
Conversation
|
||
function findKthMax(rootNode, k) { | ||
const arr = inOrderTraversal(rootNode); | ||
return arr[arr.length - k]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if k > arr.length then throw error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 🎉
|
||
function findKthMax(rootNode, k) { | ||
const arr = inOrderTraversal(rootNode); | ||
if (k < 0 || k > arr.lenth) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if k = 0
then return is undefined becuase arr[arr.length - 0 ]
|
||
function findKthMin(rootNode, k) { | ||
const arr = inOrderTraversal(rootNode); | ||
if (k < 0 || k > arr.lenth) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if k = 0
then return is undefined becuase arr[ 0 - 1 ]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍂 What's Inside?
The solution is simple, return the inorder traversal of a BST which returns a sorted array (ascending order)