tree and array python solutions