complete findBestShift() function