Amazon interview question

ancester problem and house robbery