C3 AI interview question

some dynamic programing and avl tree