How to find the leaf-only parent nodes in an n-ary tree
<p>I'm trying to solve the following algorithm:</p>

<blockquote>
  <p>You have an n-ary tree. Find all the nodes satisfying the following
  condition:</p>
  
  <ul>
  <li>the node has child node(s) but <strong>all</strong> of the child nodes are leafs (they have no children ). Return a list of leaf only parent nodes and
  their depth in the tree.</li>
  </ul>
</blockquote>

<p>So if I have the tree below, the only node satisfying the above condition is D, because it has descendants (E) but they don't have children.</p>

<pre><code>  I am root!
     /\ \
    A B  F
      /\
     C  D
         \
         E
</code></pre>

<p>I'm trying to implement this in Java but pseudocode will also work for me.
I have the tree and node structures implemented here: <a href="http://vivin.net/2010/01/30/generic-n-ary-tree-in-java/" rel="nofollow noreferrer">N-ary trees in Java</a>. </p>

<p>All I need is the algorithm.</p>