LinkedIn interview question

fairly challenging tree question