Capgemini Engineering Interview Question

linked list question along with tress