Print random element from binary tree in O(logn)
<p>Given a binary tree with <code>TreeNode</code> like:</p>

<pre><code>class TreeNode {
    int data;
    TreeNode left;
    TreeNode right;
    int size;
}
</code></pre>

<p>Where <code>size</code> is the number of nodes in the (left subtree + right subtree + 1). </p>

<blockquote>
  <p>Print a random element from the tree in O(logn) running time.</p>
</blockquote>

<p><strong>Note:</strong> This post is different from <a href="https://stackoverflow.com/questions/13300537/getting-a-random-number-from-a-binary-tree-in-olog-n-time">this</a> one, as it is clearly mentioned that we have a <code>size</code> associated with each node in this problem.</p>

<p>PS: Wrote this post inspired from <a href="https://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/">this</a>.</p>