function to get max endpoint less than or equal to given value