Let C be a subset of a compact metric space (X, d). Assume that, for every continuous function h : X → R, the restriction of h to C attains a maximum on C. Prove that C is compact.
My attempt: I intend to show that every infinite subset of C has a limit point in C. Let C' be an infinite subset of C. Since X is compact , C' has a limit point , say q, in X. Suppose q is not in C. Then I am trying to obtain some contradiction to the hypothesis i.e construct a continuous function whose restriction to C has maximum at q. But then q must be in C. I think there is something wrong in the last two lines. But this is what I have tried.
Apart from your own methods, if someone can provide a proof along the lines of the above approach then please do post it.
Thanks.