Morgan Stanley interview question

Graph,Array and Tree related Problem