Functional equations with extrema