Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike

1 Answer

0 like 0 dislike

Given a tree, you need to select a leaf and remove it. You can select any leaf if there are multiple leaves. Repeat this process until all the nodes are removed.
Return the removal sequence. Only one removal sequence is needed.

 

Requirements:

 

  • if a leaf is removed and its parent becomes a new leaf, then the new leaf must NOT be removed for the next removal unless there is no other choice.
  • Nodes need to be deleted from memory.
by Expert (34,270 points)