AMD interview question

optimize logic