Microsoft Interview Question

Had a task on strings and trees.