Caterpillar Interview Question

Data Structure and algorithm