generalize the previous check to handle -1 on either side of the