Amazon interview question

a dsa question including graph