Regarding your recent comment, doesn't this check to see if the extremum lies in the set?  This is the same as my `extrema` solution below.