Amazon interview question

Critical edge problem