title: Finding the k closest numbers to a target number in a binary search tree
body: <p>I encountered the following leetcode question and I had a question about the approach some people used to solve it. The question is:
  Given a non-empty binary search tree and a target value, find k values in the BST that are closest to the target.</p>
  
  <p>Note:
  Given target value is a floating point.</p>
  
  <p>You may assume k is always valid, that is: k ≤ total nodes.</p>
  
  <p>You are guaranteed to have only one unique set of k values in the BST that are closest to the target.</p>
  
  <p>So, what some people did is that they did an in order traversal while maintaining a k sized queue of the closest elements. During the in order traversal, if they find an element that is closer to the target than the first node in the queue, they remove the first node from the queue and add in the current value. My question is, why do they compare with the first element in the queue? Here is some code for what I am referring to: 
  <a href="https://leetcode.com/discuss/94472/inorder-one-linkedlist-java-solution-beat-85%25" rel="nofollow">https://leetcode.com/discuss/94472/inorder-one-linkedlist-java-solution-beat-85%25</a></p>