search backwards if the index is closer to the end