Last active
February 20, 2019 18:29
-
-
Save dmitry-a-morozov/970086c1f2eb7aeb6d9232515abc87a9 to your computer and use it in GitHub Desktop.
Kth largest in BST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Node<'T> = | |
| Node of value: 'T * left: Node<'T> * right: Node<'T> | |
| Empty | |
let getKthLargest(root, n) = | |
let rec loop = function | |
| Empty -> Seq.empty | |
| Node(value, left, right) -> | |
seq { | |
yield! loop right | |
yield value | |
yield! loop left | |
} | |
root |> loop |> Seq.item (n - 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment