title: To find largest element smaller than K in a BST
body: <p>Given a binary search tree and an integer K, i would like to find the largest element less than K.</p>
  
  <p>In the below tree,</p>
  
  <pre><code>for K = 13, result = 12
  for K = 10, result = 8
  for K = 1 (or) 2, result = -1
  
        10
  
    5       12
  
  2   8   11  14
  </code></pre>
  
  <p>I tried the below logic. But is there any better way to do this ?</p>
  
  <pre><code>int findNum(node* node, int K)
  {
          if(node == NULL)
          {
                  return -1;
          }
          else if(K &lt;= node-&gt;data)
          {
                  return findNum(node-&gt;left,K);
          }
          else if(K &gt; node-&gt;data)
          {
                  int t = findNum(node-&gt;right,K);
                  return t &gt; node-&gt;data ? t : node-&gt;data;
          }
  
          return -1;
  }
  </code></pre>