Amazon interview question

essentially code binary sort