Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

New Problem: kth max & min in BST #62

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

Merged
TheSTL merged 10 commits into master from problems
Oct 10, 2019
Merged

New Problem: kth max & min in BST #62

TheSTL merged 10 commits into master from problems
Oct 10, 2019

Conversation

Copy link
Member

@ashokdey ashokdey commented Oct 10, 2019
edited
Loading

πŸ‚ What's Inside?

  • Find kth maximum in a BST
  • Find kth minimum in a BST

The solution is simple, return the inorder traversal of a BST which returns a sorted array (ascending order)


function findKthMax(rootNode, k) {
const arr = inOrderTraversal(rootNode);
return arr[arr.length - k];
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done πŸŽ‰

@ashokdey ashokdey changed the title (ε‰Šι™€) New Problem: kth max in BST (ε‰Šι™€γ“γ“γΎγ§) (追記) New Problem: kth max & min in BST (θΏ½θ¨˜γ“γ“γΎγ§) Oct 10, 2019

function findKthMax(rootNode, k) {
const arr = inOrderTraversal(rootNode);
if (k < 0 || k > arr.lenth) {
Copy link
Member

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) {
Copy link
Member

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 ]

Copy link
Member

@TheSTL TheSTL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashokdey πŸ’―

@TheSTL TheSTL merged commit bfbee74 into master Oct 10, 2019
@ashokdey ashokdey deleted the problems branch October 13, 2019 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@TheSTL TheSTL TheSTL approved these changes

Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /