Amazon interview question

Live coding question on graph